Hey guys, I am trying to display a voltage on my LCD touch screen
I'm working with the TM4C123GH6PM.
The problem is that i can't seem to update the value of ADC.
Does anyone have an idea of how to do this? (see last function p
//***************************************************************************** // // scribble.c - A simple scribble pad to demonstrate the touch screen driver. // //***************************************************************************** #include <stdint.h> #include <stdbool.h> #include "inc/hw_memmap.h" #include "inc/hw_nvic.h" #include "inc/hw_sysctl.h" #include "inc/hw_types.h" #include "driverlib/fpu.h" #include "driverlib/gpio.h" #include "driverlib/flash.h" #include "driverlib/sysctl.h" #include "driverlib/systick.h" #include "driverlib/uart.h" #include "driverlib/udma.h" #include "driverlib/rom.h" #include "grlib/grlib.h" #include "grlib/widget.h" #include "grlib/canvas.h" #include "grlib/checkbox.h" #include "grlib/container.h" #include "grlib/pushbutton.h" #include "grlib/radiobutton.h" #include "grlib/slider.h" #include "utils/ustdlib.h" #include "drivers/Kentec320x240x16_ssd2119_8bit.h" //#include "drivers/sound.h" #include "drivers/touch.h" //#include "drivers/set_pinout.h" #include "images.h" #define ADC1_ISC_R (*((volatile unsigned long *)0x4003900C)) #define GPIO_PORTF_DATA_R (*((volatile unsigned long *)0x400253FC)) #define ADC0_SSFIFO3_R (*((volatile unsigned long *)0x400380A8)) #define ADC_SSFIFO3_DATA_M 0x00000FFF // Conversion Result Data void Init_ADC (void); //***************************************************************************** // //! \addtogroup example_list //! <h1>Scribble Pad (scribble)</h1> //! //! The scribble pad provides a drawing area on the screen. Touching the //! screen will draw onto the drawing area using a selection of fundamental //! colors (in other words, the seven colors produced by the three color //! channels being either fully on or fully off). Each time the screen is //! touched to start a new drawing, the drawing area is erased and the next //! color is selected. // //***************************************************************************** //***************************************************************************** // // The error routine that is called if the driver library encounters an error. // //***************************************************************************** #ifdef DEBUG void __error__(char *pcFilename, unsigned long ulLine) { } #endif #define __FPU_PRESENT 1 #define ARM_MATH_CM4 #include "arm_math.h" #include "arm_const_structs.h" volatile float32_t ADCvalue; volatile float32_t Voltage; volatile float32_t Pressure; //***************************************************************************** // // The DMA control structure table. // //***************************************************************************** #ifdef ewarm #pragma data_alignment=1024 tDMAControlTable sDMAControlTable[64]; #elif defined(ccs) #pragma DATA_ALIGN(sDMAControlTable, 1024) tDMAControlTable sDMAControlTable[64]; #else tDMAControlTable sDMAControlTable[64] __attribute__ ((aligned(1024))); #endif //***************************************************************************** // // Forward declarations for the globals required to define the widgets at // compile-time. // //***************************************************************************** void OnPrevious(tWidget *pWidget); void OnNext(tWidget *pWidget); void OnIntroPaint(tWidget *pWidget, tContext *pContext); void OnPrimitivePaint(tWidget *pWidget, tContext *pContext); void OnCanvasPaint(tWidget *pWidget, tContext *pContext); void OnCheckChange(tWidget *pWidget, uint32_t bSelected); void OnButtonPress(tWidget *pWidget); void OnRadioChange(tWidget *pWidget, uint32_t bSelected); void OnSliderChange(tWidget *pWidget, int32_t lValue); extern tCanvasWidget g_psPanels[]; volatile int z=0; //***************************************************************************** // // The first panel, which contains introductory text explaining the // application. // //***************************************************************************** Canvas(g_sIntroduction, g_psPanels, 0, 0, &g_sKentec320x240x16_SSD2119, 0, 24, 320, 166, CANVAS_STYLE_APP_DRAWN, 0, 0, 0, 0, 0, 0, OnIntroPaint); //***************************************************************************** // // The second panel, which demonstrates the graphics primitives. // //***************************************************************************** tContainerWidget g_psRadioContainers[]; tCanvasWidget g_psRadioButtonIndicators[] = { CanvasStruct(g_psRadioContainers, g_psRadioButtonIndicators + 1, 0, &g_sKentec320x240x16_SSD2119, 120, 62, 20, 20, CANVAS_STYLE_IMG, 0, 0, 0, 0, 0, g_pucLightOff, 0), CanvasStruct(g_psRadioContainers, g_psRadioButtonIndicators + 2, 0, &g_sKentec320x240x16_SSD2119, 120, 107, 20, 20, CANVAS_STYLE_IMG, 0, 0, 0, 0, 0, g_pucLightOff, 0), CanvasStruct(g_psRadioContainers, 0, 0, &g_sKentec320x240x16_SSD2119, 120, 152, 20, 20, CANVAS_STYLE_IMG, 0, 0, 0, 0, 0, g_pucLightOff, 0), }; tCanvasWidget g_psPushButtonIndicators[] = { CanvasStruct(g_psRadioContainers + 1, 0, 0, &g_sKentec320x240x16_SSD2119, 190, 115, 20, 20, CANVAS_STYLE_IMG, 0, 0, 0, 0, 0, g_pucLightOff, 0), }; tCanvasWidget g_psText[] = { CanvasStruct(g_psRadioContainers + 2, 0, 0, &g_sKentec320x240x16_SSD2119, 120, 35, 195, 76, CANVAS_STYLE_TEXT,ClrMidnightBlue, ClrWhite, ClrWhite, &g_sFontCm22, "NASER", 0, 0), }; tRadioButtonWidget g_psRadioButtons1[] = { RadioButtonStruct(g_psRadioContainers, g_psRadioButtons1 + 1, 0, &g_sKentec320x240x16_SSD2119, 10, 50, 100, 45, RB_STYLE_TEXT, 16, 0, ClrLightGreen, ClrWhite, &g_sFontCm20, " mL H20", 0, OnRadioChange), RadioButtonStruct(g_psRadioContainers, g_psRadioButtons1 + 2, 0, &g_sKentec320x240x16_SSD2119, 10, 95, 100, 45, RB_STYLE_TEXT, 16, 0, ClrLightGreen, ClrWhite, &g_sFontCm20, " milliBar", 0, OnRadioChange), RadioButtonStruct(g_psRadioContainers, g_psRadioButtonIndicators, 0, &g_sKentec320x240x16_SSD2119, 10, 140, 100, 45, RB_STYLE_TEXT, 16, 0, ClrLightGreen, ClrWhite, &g_sFontCm20, " Pascal", 0, OnRadioChange), }; #define NUM_RADIO1_BUTTONS (sizeof(g_psRadioButtons1) / \ sizeof(g_psRadioButtons1[0])) tPushButtonWidget g_psPushButtons[] = { RectangularButtonStruct(g_psRadioContainers + 1, g_psPushButtons + 1, 0, &g_sKentec320x240x16_SSD2119, 170, 140, 70, 40, PB_STYLE_FILL | PB_STYLE_OUTLINE | PB_STYLE_TEXT, ClrRed, ClrBlack, ClrWhite, ClrWhite, &g_sFontCm22, "Hold", 0, 0, 0, 0, OnButtonPress), RectangularButtonStruct(g_psRadioContainers + 1, g_psRadioButtonIndicators + 3, 0, &g_sKentec320x240x16_SSD2119, 243, 140, 70, 40, PB_STYLE_FILL | PB_STYLE_OUTLINE | PB_STYLE_TEXT, ClrLightGreen, ClrBlack, ClrWhite, ClrWhite, &g_sFontCm22, "Save", 0, 0, 0, 0, OnButtonPress), }; #define NUM_PUSH_BUTTONS (sizeof(g_psPushButtons) / \ sizeof(g_psPushButtons[0])) unsigned long g_ulButtonState; tContainerWidget g_psRadioContainers[] = { ContainerStruct(g_psPanels + 1, g_psRadioContainers + 1 , g_psRadioButtons1, &g_sKentec320x240x16_SSD2119, 5, 27, 148, 160, CTR_STYLE_OUTLINE | CTR_STYLE_TEXT, 0, ClrWhite, ClrWhite, &g_sFontCm20, "Unit"), ContainerStruct(g_psPanels + 1, g_psRadioContainers + 2, g_psPushButtons, &g_sKentec320x240x16_SSD2119, 167, 110, 148, 50, CTR_STYLE_OUTLINE | CTR_STYLE_TEXT, 0, 0, 0, &g_sFontCm20, "Fonctions"), ContainerStruct(g_psPanels + 1, 0, g_psText, &g_sKentec320x240x16_SSD2119, 167, 27, 148, 75, CTR_STYLE_OUTLINE | CTR_STYLE_TEXT, 0, ClrWhite, ClrWhite, &g_sFontCm20, "Pression"), }; //***************************************************************************** // // An array of canvas widgets, one per panel. Each canvas is filled with // black, overwriting the contents of the previous panel. // //***************************************************************************** tCanvasWidget g_psPanels[] = { CanvasStruct(0, 0, &g_sIntroduction, &g_sKentec320x240x16_SSD2119, 0, 24, 320, 166, CANVAS_STYLE_FILL, ClrBlack, 0, 0, 0, 0, 0, 0), CanvasStruct(0, 0, g_psRadioContainers, &g_sKentec320x240x16_SSD2119, 0, 24, 320, 166, CANVAS_STYLE_FILL, ClrBlack, 0, 0, 0, 0, 0, 0), }; //***************************************************************************** // // The number of panels. // //***************************************************************************** #define NUM_PANELS (sizeof(g_psPanels) / sizeof(g_psPanels[0])) //***************************************************************************** // // The names for each of the panels, which is displayed at the bottom of the // screen. // //***************************************************************************** char *g_pcPanelNames[] = { " Overview ", " Mesurements " }; //***************************************************************************** // // The buttons and text across the bottom of the screen. // //***************************************************************************** RectangularButton(g_sPrevious, 0, 0, 0, &g_sKentec320x240x16_SSD2119, 0, 190, 80, 50, PB_STYLE_FILL, ClrBlack, ClrBlack, 0, ClrWhite, &g_sFontCm20, "-", g_pucBlue50x50, g_pucBlue50x50Press, 0, 0, OnPrevious); Canvas(g_sTitle, 0, 0, 0, &g_sKentec320x240x16_SSD2119, 50, 190, 220, 50, CANVAS_STYLE_TEXT | CANVAS_STYLE_TEXT_OPAQUE, 0, 0, ClrGold, &g_sFontCm20, 0, 0, 0); RectangularButton(g_sNext, 0, 0, 0, &g_sKentec320x240x16_SSD2119, 250, 190, 80, 50, PB_STYLE_IMG | PB_STYLE_TEXT, ClrBlack, ClrBlack, 0, ClrWhite, &g_sFontCm20, "+", g_pucBlue50x50, g_pucBlue50x50Press, 0, 0, OnNext); //***************************************************************************** // // The panel that is currently being displayed. // //***************************************************************************** unsigned long g_ulPanel; //***************************************************************************** // // Handles presses of the previous panel button. // //***************************************************************************** void OnPrevious(tWidget *pWidget) { // // There is nothing to be done if the first panel is already being // displayed. // if(g_ulPanel == 0) { return; } // // Remove the current panel. // WidgetRemove((tWidget *)(g_psPanels + g_ulPanel)); // // Decrement the panel index. // g_ulPanel--; // // Add and draw the new panel. // WidgetAdd(WIDGET_ROOT, (tWidget *)(g_psPanels + g_ulPanel)); WidgetPaint((tWidget *)(g_psPanels + g_ulPanel)); // // Set the title of this panel. // CanvasTextSet(&g_sTitle, g_pcPanelNames[g_ulPanel]); WidgetPaint((tWidget *)&g_sTitle); // // See if this is the first panel. // if(g_ulPanel == 0) { // // Clear the previous button from the display since the first panel is // being displayed. // PushButtonImageOff(&g_sPrevious); PushButtonTextOff(&g_sPrevious); PushButtonFillOn(&g_sPrevious); WidgetPaint((tWidget *)&g_sPrevious); } // // See if the previous panel was the last panel. // if(g_ulPanel == (NUM_PANELS - 2)) { // // Display the next button. // PushButtonImageOn(&g_sNext); PushButtonTextOn(&g_sNext); PushButtonFillOff(&g_sNext); WidgetPaint((tWidget *)&g_sNext); } // // Play the key click sound. // // SoundPlay(g_pusKeyClick, sizeof(g_pusKeyClick) / 2); } //***************************************************************************** // // Handles presses of the next panel button. // //***************************************************************************** void OnNext(tWidget *pWidget) { // // There is nothing to be done if the last panel is already being // displayed. // if(g_ulPanel == (NUM_PANELS - 1)) { return; } // // Remove the current panel. // WidgetRemove((tWidget *)(g_psPanels + g_ulPanel)); // // Increment the panel index. // g_ulPanel++; // // Add and draw the new panel. // WidgetAdd(WIDGET_ROOT, (tWidget *)(g_psPanels + g_ulPanel)); WidgetPaint((tWidget *)(g_psPanels + g_ulPanel)); // // Set the title of this panel. // CanvasTextSet(&g_sTitle, g_pcPanelNames[g_ulPanel]); WidgetPaint((tWidget *)&g_sTitle); // // See if the previous panel was the first panel. // if(g_ulPanel == 1) { // // Display the previous button. // PushButtonImageOn(&g_sPrevious); PushButtonTextOn(&g_sPrevious); PushButtonFillOff(&g_sPrevious); WidgetPaint((tWidget *)&g_sPrevious); } // // See if this is the last panel. // if(g_ulPanel == (NUM_PANELS - 1)) { // // Clear the next button from the display since the last panel is being // displayed. // PushButtonImageOff(&g_sNext); PushButtonTextOff(&g_sNext); PushButtonFillOn(&g_sNext); WidgetPaint((tWidget *)&g_sNext); } } //***************************************************************************** // // Handles paint requests for the introduction canvas widget. // //***************************************************************************** void OnIntroPaint(tWidget *pWidget, tContext *pContext) { // // Display the Overview of the application. // GrContextFontSet(pContext, &g_sFontCm18); GrContextForegroundSet(pContext, ClrWhite); GrStringDraw(pContext, "This instrument measures the pressure with accuracy", -1, 0, 32, 0); GrStringDraw(pContext, "accuracy.", -1, 0, 50, 0); GrStringDraw(pContext, "Many features are available in this ", -1, 0, 74, 0); GrStringDraw(pContext, "application.", -1, 0, 92, 0); GrStringDraw(pContext, "You can easily change the Unit of the", -1, 0, 110, 0); GrStringDraw(pContext, "pressure and store up to 15 mesures", -1, 0, 128, 0); GrStringDraw(pContext, "Navigate using + and - ", -1, 0, 146, 0); } //***************************************************************************** // // Handles press notifications for the push button widgets. // //***************************************************************************** void OnButtonPress(tWidget *pWidget) { unsigned long ulIdx; // // Find the index of this push button. // for(ulIdx = 0; ulIdx < NUM_PUSH_BUTTONS; ulIdx++) { if(pWidget == (tWidget *)(g_psPushButtons + ulIdx)) { break; } } // // Return if the push button could not be found. // if(ulIdx == NUM_PUSH_BUTTONS) { return; } // // Toggle the state of this push button indicator. // g_ulButtonState ^= 1 << ulIdx; // // Set the matching indicator based on the selected state of the check box. // CanvasImageSet(g_psPushButtonIndicators + ulIdx, (g_ulButtonState & (1 << ulIdx)) ? g_pucLightOn : g_pucLightOff); WidgetPaint((tWidget *)(g_psPushButtonIndicators + ulIdx)); } //***************************************************************************** // // Handles change notifications for the radio button widgets. // //***************************************************************************** void OnRadioChange(tWidget *pWidget, uint32_t bSelected) { unsigned long ulIdx; // // Find the index of this radio button in the first group. // for(ulIdx = 0; ulIdx < NUM_RADIO1_BUTTONS; ulIdx++) { if(pWidget == (tWidget *)(g_psRadioButtons1 + ulIdx)) { break; } } // // See if the radio button was found. // if(ulIdx == NUM_RADIO1_BUTTONS) return; // // Set the matching indicator based on the selected state of the radio // button. // CanvasImageSet(g_psRadioButtonIndicators + ulIdx, bSelected ? g_pucLightOn : g_pucLightOff); WidgetPaint((tWidget *)(g_psRadioButtonIndicators + ulIdx)); } //***************************************************************************** // // A simple demonstration of the features of the Stellaris Graphics Library. // //***************************************************************************** int main(void) { tContext sContext; tRectangle sRect; FPUEnable(); FPULazyStackingEnable(); // // Set the clocking to run directly from the crystal. // SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_XTAL_16MHZ | SYSCTL_OSC_MAIN); Init_ADC (); // // Initialize the display driver. // Kentec320x240x16_SSD2119Init(); // // Initialize the graphics context. // GrContextInit(&sContext, &g_sKentec320x240x16_SSD2119); // // Fill the top 24 rows of the screen with blue to create the banner. // sRect.i16XMin = 0; sRect.i16YMin = 0; sRect.i16XMax = GrContextDpyWidthGet(&sContext) - 1; sRect.i16YMax = 23; GrContextForegroundSet(&sContext, ClrDarkBlue); GrRectFill(&sContext, &sRect); // // Put a white box around the banner. // GrContextForegroundSet(&sContext, ClrWhite); GrRectDraw(&sContext, &sRect); // // Put the application name in the middle of the banner. // GrContextFontSet(&sContext, &g_sFontCm20); GrStringDrawCentered(&sContext, "Pressure Mesurement", -1, GrContextDpyWidthGet(&sContext) / 2, 10, 0); // // Configure and enable uDMA // SysCtlPeripheralEnable(SYSCTL_PERIPH_UDMA); SysCtlDelay(10); uDMAControlBaseSet(&sDMAControlTable[0]); uDMAEnable(); // // Initialize the touch screen driver and have it route its messages to the // widget tree. // TouchScreenInit(); TouchScreenCallbackSet(WidgetPointerMessage); // // Add the title block and the previous and next buttons to the widget // tree. // WidgetAdd(WIDGET_ROOT, (tWidget *)&g_sPrevious); WidgetAdd(WIDGET_ROOT, (tWidget *)&g_sTitle); WidgetAdd(WIDGET_ROOT, (tWidget *)&g_sNext); // // Add the first panel to the widget tree. // g_ulPanel = 0; WidgetAdd(WIDGET_ROOT, (tWidget *)g_psPanels); CanvasTextSet(&g_sTitle, g_pcPanelNames[0]); // // Issue the initial paint request to the widgets. // WidgetPaint(WIDGET_ROOT); // // Loop forever handling widget messages. // while(1) { // // Process any messages in the widget message queue. // WidgetMessageQueueProcess(); } } void ADC1SS3_Handler(void) { char str[10]; uint32_t n; tRectangle sRect; ADC1_ISC_R = 0x00000008; ADCvalue = ADC0_SSFIFO3_R & ADC_SSFIFO3_DATA_M; // aquisition de la tension n=usprintf(str, "%u", ADCvalue); CanvasTextSet(g_psText, str); //REFRESH DISPLAY }