#INT_EXT
void EXT_isr(void)
{
flags.fremote = 1;
clear_interrupt(INT_EXT);
}
#use RS232(baud=9600, xmit=PIN_B7, rcv=PIN_B5,
stream=RADIO)
typedef struct{
unsigned int8 fremote:1;
}FFLAGS;
FFLAGS flags;
unsigned int8 msgON[3];
unsigned int8 msgOFF[4];
unsigned int8 aryIndex;
unsigned int8 nextState;
When the pushbutton is depressed, the fremote flag is
set and the external interrupt flag is cleared. It is always
best to do as little as possible within the interrupt handler.
The fremote flag will be set within the pushbutton
interrupt handler when the pushbutton is depressed.
We will handle the pushbutton physics following the
execution of the interrupt handler. Let’s load our message
arrays in the initialization function:
Normally, a remote control device will send a sequence
of binary characters that are decoded at the receiving end.
In this case, I’m going to use human readable messages
which will be stored in the arrays msgON and msgOFF.
void init(void)
{
hw_init();
output_low(RED_LED); //Both LEDs off
output_low(GREEN_LED);
Rather than use the mundane i or x as an array index
pointer, we will use the aryIndex variable as our array
pointer. Our remote control application is very simple and
consists of two states (ON and OFF). The nextState
variable will determine which state is to be entered with
the next pushbutton depression.
msgON[0] = ‘O’;
msgON[1] = ‘N’;
msgON[2] = 0x00;
msgOFF[0] = ‘O’;
msgOFF[1] = ‘F’;
msgOFF[2] = ‘F’;
msgOFF[3] = 0x00;
Our pushbutton interrupt handler is to the point:
nextState = 0;
flags.fremote = 0;
The Convenient All-in-One Solution
for Custom-Designed Front Panels & Enclosures
FREE
Software
ONLY $90.24
with custom
logo engraving
You design it
t
We machine it
to your specifications using
our FREE CAD software,
Front Panel Designer
and ship to you a
professionally finished product,
no minimum quantity required
;;;;; ; Cost effective prototypes and production
runs with no setup charges
;;;;; Powder-coated and anodized finishes in
various colors
;;;;; Select from aluminum, acrylic or provide
your own material
;;;;Standard lead time in 5 days or express
manufacturing in 3 or 1 days
FrontPanelExpress.com
1(800)FPE-9060
56 November 2014