Microchip Technology DM300019 Data Sheet

Page of 50
Demonstration Program Operation
© 2006 Microchip Technology Inc.
DS51584B-page 27
3.4
DEMONSTRATION CODE OPERATION
The following sections describe in more detail how the demonstration programs 
interact with and take advantage of key dsPIC DSC, DSP and peripheral features. Full 
details on the peripheral functionality and associated tasks are presented later in this 
document.
3.4.1
Interrupt Processing 
The demonstration code samples switches S1 and S2 and uses their status to operate 
the LEDs associated with processor ports RD4 and RD5, respectively. If S1 is pressed, 
it sets program flag “LED1on”. If S1 is pressed again, it resets program flag LED1on. 
Similarly, if S2 is pressed, it toggles program flag LED2on.
Another interrupt routine checks flags LED1on and LED2on every 500 milliseconds. If 
the LED1on is true, the LED labeled RD4 is toggled on and off every 0.5 seconds, 
causing the LED to blink. If LED1on is not true, the LED remains off.
This demo program is illustrated in Figure 3-1. 
FIGURE 3-1:
INTERRUPT PROCESSING FLOW DIAGRAM
START
INIT TIMER 1
LED1on = LED1on
S1 Pressed?
S2 Pressed?
LED2on = LED2on
S1 Released?
S2 Released?
Yes
No
Yes
Yes
Yes
Yes
No
No
No
Start of 0.5 sec 
Timer1 Init
LED1on Flag Set?
RD4 = RD4
Turn RD4 Off
LED2on Flag Set?
RD5 = RD5
Turn RD5 Off
Return 
No
Yes
No
For 0.5 Sec Interval