User manual

Table Of Contents
PICDEM
TM
Lab Development Board User’s Guide
DS41369A-page 54 © 2009 Microchip Technology Inc.
The INTCON register is needed as well to implement the interrupt-on-change feature.
Again the GIE bit needs to be set to enable any interrupts used on the microcontroller.
To configure for an interrupt-on-change, the PORTA/PORTB Change Interrupt Enable
bit (RABIE) must be set along with the individual enable bits in the IOCA register. On
an interrupt-on-change for configured pins, the PORTA/PORTB Change Interrupt Flag
bit (RABIF) will be set. To detect a logic change on a port pin, the firmware needs to
know what has changed. Therefore, PORTA must be read before an
interrupt-on-change can occur. Reading PORTA retains, or latches, the current value
on the RA2 pin for later reference. In the event that the signal on the RA2 pin changes
and a mismatch with the reference value occurs, an interrupt will result.
The main() software flowchart for this lab remains the same as that in Figure 3-24 of
the previous lab. The Interrupt Service Routine changes since it now must determine
whether the interrupt occurred due to a high-to-low or low-to-high transition on pin RA2.
The ISR flowchart is shown in Figure 3-25.
FIGURE 3-25: PB_PRESSISR FLOWCHART FOR LAB 7
pb_pressISR()
RABIE and RABIF
bits set
?
RETURN
Clear RABIF flag
YES
RA2 pin = 0
?
direction = 1
Delay for 5mS
NO
RA2 pin = 0
?
RA2 pin = 1
?
Delay for 5mS
RA2 pin = 1
?
direction = 1
Read PORTA
YES
YES
NO
NO
NO