case 1:
if(flags.fremote == 1)
{
disable_interrupts(INT_EXT);
delay_ms(100);
while(input(PBTN));
while(!input(PBTN));
for(aryIndex = 0;aryIndex <
2;aryIndex++)
{
fprintf(RADIO,”%c”,msgON
[aryIndex]);
}
fprintf(RADIO,” “);
output_high(GREEN_LED);
delay_ms(500);
output_low(GREEN_LED);
nextState = 0;
flags.fremote = 0;
while(!input(PBTN));
enable_interrupts(INT_EXT_H2L);
}
break;
}
}
}
enable_interrupts(INT_EXT_H2L);
}
break;
The mini state machine runs continuously within the
while(TRUE) loop. If the nextState value is equal to zero,
the case0 code executes. The fremote flag is checked to
make sure that the pushbutton has indeed fired the
external interrupt. To keep things from getting out of hand,
we disable the external interrupt until the previously fired
external interrupt is serviced.
The pushbutton is a mechanical device that bounces
all over the place when depressed and released. Upon
entering the case0 code, we handle the pushbutton
bounce by delaying 100 mS and waiting for the
pushbutton to be released. If the bounce condition
happens to satisfy the while(input(PBTN)) and
while(!input(PBTN)) traps, the interrupt handler will
execute normally and make another attempt to filter the
bounce condition at the end of the interrupt handler
code. The state machine does not move until the
pushbutton is released.
I have captured the results of depressing and releasing
the pushbutton in Screenshot 3.
Designing Outside of the Box
The Rapid USB prototyping stick provides everything
you need to quickly assemble some rather powerful
applications with little effort and minimal extraneous
hardware. NV
The code within the case0 state should be very
familiar as it is based on our very first LED blinker
application. The case1 code is identical with the exception
of the message contents:
PBP3
Student - $49.95 Silver Edition - $119.95 Gold Edition - $269.95 FREE
PICBASIC PRO™ Compiler
BASIC compiler for Microchip PIC® microcontrollers
Download FREE trial now
Simple, Reliable, Affordable
WWW.PBP3.COM
PICBASIC and PICBASIC PRO are trademarks of Microchip Technology Inc. in the USA and other countries. PIC is a registered trademark of Microchip Technology Inc. in the USA and other countries.
58 November 2014