Hi,
There is a problem on blinking the LED by using the timer interrupt with LCD. Is there anyone can help? I trying to combine lab 4 and lab 10 of the workshop.
#include <stdint.h>
#include <stdbool.h>
#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "driverlib/interrupt.h"
#include "driverlib/sysctl.h"
#include "driverlib/gpio.h"
#include "grlib/grlib.h"
#include "grlib/widget.h"
#include "grlib/canvas.h"
#include "grlib/pushbutton.h"
#include "utils/ustdlib.h"
#include "grlib/container.h"
#include "Kentec320x240x16_ssd2119_8bit.h"
#include "touch.h"
#include "driverlib/timer.h"
extern tCanvasWidget g_sHeading;
extern tCanvasWidget g_sBackground;
extern tPushButtonWidget g_sPushBtn0;
extern tPushButtonWidget g_sPushBtn1;
extern tPushButtonWidget g_sPushBtn2;
extern tPushButtonWidget g_sPushBtn3;
extern const uint8_t g_pui8Image[];
tContext sContext;
tRectangle sRect;
void StartButtonPress(tWidget *pWidget); // define of start button
void ReleaseButtonPress(tWidget *pWidget); // define of release button
void EmergencyButtonPress(tWidget *pWidget); // define of emergency stop button
// ************************* Heading **********************************
Canvas(g_sHeading, &g_sBackground,0, &g_sPushBtn0,
&g_sKentec320x240x16_SSD2119, 0, 0, 320, 30,
(CANVAS_STYLE_FILL | CANVAS_STYLE_OUTLINE | CANVAS_STYLE_TEXT),
ClrBlack, ClrWhite, ClrCyan , g_psFontCm22b, "Nasogastric Intubation", 0, 0);
// *********************** Background ******************************************
Canvas(g_sBackground, WIDGET_ROOT, 0, &g_sHeading,
&g_sKentec320x240x16_SSD2119, 0, 23, 320, (240 - 23),
CANVAS_STYLE_FILL, ClrBlack, 0, 0, 0, 0, 0, 0);
// ***************** Start button *************************
RectangularButton(g_sPushBtn0, &g_sHeading, &g_sPushBtn1, 0,
&g_sKentec320x240x16_SSD2119, 230, 60, 80, 35,
(PB_STYLE_OUTLINE | PB_STYLE_TEXT_OPAQUE | PB_STYLE_TEXT |
PB_STYLE_FILL), ClrSnow, ClrYellow, ClrRed, ClrLightGreen,
g_psFontCmss22b, "Start",0,0,0,0, StartButtonPress);
// ******************* Release button *****************
RectangularButton(g_sPushBtn1, &g_sHeading,&g_sPushBtn2, 0,
&g_sKentec320x240x16_SSD2119, 220, 120, 90, 35,
(PB_STYLE_OUTLINE | PB_STYLE_TEXT_OPAQUE | PB_STYLE_TEXT |
PB_STYLE_FILL), ClrSnow, ClrYellow, ClrRed, ClrBlue,
g_psFontCmss22b, "Release",0,0,0,0, ReleaseButtonPress);
// ******************* Emergency Stop button **************************
RectangularButton(g_sPushBtn2, &g_sHeading,0 , 0,
&g_sKentec320x240x16_SSD2119, 210, 180, 100, 35,
(PB_STYLE_OUTLINE | PB_STYLE_TEXT_OPAQUE | PB_STYLE_TEXT |
PB_STYLE_FILL), ClrSnow, ClrYellow, ClrRed, ClrRed,
g_psFontCmss18b, "Emergency",0,0,0,0, EmergencyButtonPress);
// ******************** Green LED light up when start button pressed **********************
//bool g_GreenLedOn = false;
void StartButtonPress(tWidget *pWidget)
{
uint32_t ui32Period;
SysCtlClockSet(SYSCTL_SYSDIV_5|SYSCTL_USE_PLL|SYSCTL_XTAL_16MHZ|SYSCTL_OSC_MAIN);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3);
SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0);
TimerConfigure(TIMER0_BASE, TIMER_CFG_PERIODIC);
ui32Period = (SysCtlClockGet() / 10) / 2;
TimerLoadSet(TIMER0_BASE, TIMER_A, ui32Period -1);
IntEnable(INT_TIMER0A);
TimerIntEnable(TIMER0_BASE, TIMER_TIMA_TIMEOUT);
IntMasterEnable();
TimerEnable(TIMER0_BASE, TIMER_A);
while(1)
{
}
}
// ************* Red LED light up when emergency button pressed **********************
bool g_RedLedOn = false;
void EmergencyButtonPress(tWidget *pWidget)
{
g_RedLedOn =! g_RedLedOn;
if(g_RedLedOn)
{
//GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1, 0x02);
}
else
{
//GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1, 0x00);
}
}
// ********************* Blue LED light up when release button pressed *****************
bool g_BlueLedOn = false;
void ReleaseButtonPress(tWidget *pWidget)
{
g_BlueLedOn =! g_BlueLedOn;
if(g_BlueLedOn)
{
GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_2, 0x04);
}
else
{
GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_2, 0x00);
}
}
int main(void)
{
SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3);
GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3, 0x00);
Kentec320x240x16_SSD2119Init();
TouchScreenInit();
TouchScreenCallbackSet(WidgetPointerMessage);
WidgetAdd(WIDGET_ROOT, (tWidget *)&g_sBackground);
WidgetPaint(WIDGET_ROOT);
while(1)
{
WidgetMessageQueueProcess();
}
}
// ******************************** Timer interrupt **************************************
void Timer0IntHandler(void)
{
// Clear the timer interrupt
TimerIntClear(TIMER0_BASE, TIMER_TIMA_TIMEOUT);
// Read the current state of the GPIO pin and
// write back the opposite state
if(GPIOPinRead(GPIO_PORTF_BASE, GPIO_PIN_2))
{
GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3, 0);
}
else
{
GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_2, 4);
}
}
Thank you. Appreciate your help.