User manual

Table Of Contents
PICDEM
TM
Lab Development Board User’s Guide
DS41369A-page 50 © 2009 Microchip Technology Inc.
Referring to the flowchart in Figure 3-24, the PB_PressISR() replaces the
Get_Inputs() used in Lab 4 with a few additions. At the beginning of the ISR, the
INTE and INTF bits are first checked to ensure that the RA2/INT external interrupt is
indeed enabled and that the flag is set indicating that an RA2/INT external interrupt has
occurred. Determining the source of an interrupt becomes especially important if
multiple peripherals are configured to cause an interrupt. The ISR then clears the
RA2/INT external interrupt flag so that subsequent interrupts will be registered. The
ISR then performs the RA2 check along with the debounce routine that was discussed
in the previous lab.
3.4.5.3 PROCEDURE
Using the firmware developed in the previous lab, make the following changes:
1. Copy/paste the Interrupt Service Routine in Figure 3-23 at the top of the firmware
source file under the section labeled:
/**INTERRUPT CODE***************************************/
EXAMPLE 3-23: PB_PRESSISR() CODE FOR GPIO LAB 6
/*---------------------------------------------------------
-
Subroutine: Interrupt Service Routine
Parameters: none
Returns:nothing
Synopsis:Execute this code on any interrupt
---------------------------------------------------------*/
void interrupt PB_PressISR(void)
{
//Check to see if the interrupt was caused by
//the external interrupt on RA2
//If so, clear the external interrupt flag
//to allow subsequent interrupts to be detected
if(INTE && INTF) INTF = 0;
//Check to see if the RA2 pin is 0
//(i.e. push button pressed)
if(RA2 == 0)
{
//If RA2 is 0 delay for 5mS to filter
//any switch bounce
Delay_5mS();
//Check to see if RA2 is still 0
//If so, toggle the direction bit
if(RA2 == 0) direction ^= 1;
}
//If RA2 is not 0, keep direction value
//the same as it was
else direction = direction;
}