lpcware

enquiry on interrupt

Discussion created by lpcware Employee on Jun 15, 2016
Latest reply on Jun 15, 2016 by lpcware
Content originally posted in LPCWare by jx1 on Mon Aug 05 22:39:01 MST 2013
Hi everyone,

I am using a switch as interrupt. So whenever I turn the switch off, it will switch off my lamp.  My program does not seem to be working. How come when I turn the switch off, my lamp would not switch off? :~  Please take a look at the source code shown below.Thanks in advance!

volatile uint32_t pin9_counter = 0;
typedef enum SysState
{
System_Start   = 0,
System_Idle,
System_Confirm,
System_Occupy,
System_Vacant
} SysState;

void PIOINT0_IRQHandler(void)
{
  uint32_t regVal;
  if (GPIOIntStatus( PORT0, 9 ))
  {
    pin9_counter = 1;
  }
  else
      pin9_counter = 0;
      GPIOIntClear( PORT0, 9);
      return;
}

void DALI_Thread(void)
{
    bool dali_cmd;
    uint16_t forwardFrame;
    uint8_t  busy_led_state = 0;
    int lastTicks;

    DALI_Init();
   
GPIOInit();


GPIOSetDir (PORT0, 9, 0 );  
GPIOSetInterrupt( PORT0, 9, 0, 0, 1 );
GPIOIntEnable( PORT0, 9);

State = System_Start;

while(1)
{
switch (State)
{
case System_Start:
        pin9_counter = 1;
DALI_Send((0xFE << 8 ) + 0xFE); // Turn on the light 100% brightness
printf("System Start State\n");

if (pin9_counter == 0)
State = System_Idle;
    break;

/*========================================================================================================================*/
case System_Idle:

DALI_Send((0xFE << 8 ) + 0x00);
printf("System Idle State\n");



if (pin9_counter == 1)
{
State = System_Start;
break;
}

Outcomes