
Comparator Peripheral Labs
FIGURE 4-7:
TMR0_ISR FLOWCHART FOR COMPARATOR LAB 3
TMR0_ISR()
T0IF = 1
?
YES
Clear T0IF Flag
Turn off Timer1
NO
Keep PORTC the same
END
Assign PORTC the T1MRH value
shifted 4 bits to the right
Clear the Timer1 result register
pair TMR1H:TMR1L
Turn on Timer1
The TMR0_ISR() first checks if a Timer0 interrupt has occurred (good programming
practice). If so, then the Timer0 interrupt flag is cleared and Timer1 is turned off to stop
counting the oscillator clock pulses on the T1CKI pin. Next, the 4 MSbs of the Timer1
16-bit result is assigned to the RC0, RC1, RC2 and RC3 pins to light the associated
LEDs. Finally, the Timer1 result register pair are cleared and Timer1 is turned on to
begin a new count.
4.2.6.3
PROCEDURE
Using the firmware developed in the previous lab, make the following changes:
1. Copy/paste the code in Example 4-4 into the top of the main firmware source file
under the heading labeled:
//----------------INTERRUPT CODE---------------
? 2009 Microchip Technology Inc.
DS41369A-page 71