Information

TIMER1 MODULE
DS80233C-page 4 © 2007 Microchip Technology Inc.
EXAMPLE 1: PIC12/PIC14/PIC16 INTERRUPT SERVICE ROUTINE
EXAMPLE 2: PIC18 HIGH PRIORITY INTERRUPT SERVICE ROUTINE
EXAMPLE 3: PIC18 LOW PRIORITY INTERRUPT SERVICE ROUTINE
Note: These instructions are required based on the function of the ISR. If the only code in the ISR is to reload
Timer1, then they are not required, but may be required if additional code is added.
ISR @ 0x004 ; (3-4Tcy), fixed interrupt latency
MOVWF w_temp ; (1Tcy), save off current W register contents
MOVF STATUS,w ; (1Tcy), move status register into W register
MOVWF status_temp ; (1Tcy), save off contents of STATUS register
BANKSEL PIR ; (2Tcy), choose correct SFR bank
BTFSS PIR,TMRIF ; (2Tcy), did a Timer1 overflow occur?
GOTO EXIT ; No
RELOAD
BSF TMR1H,7 ; (1Tcy) Yes, reload for a 1 second overflow
EXIT
MOVF status_temp,w ; retrieve copy of STATUS register
MOVWF STATUS ; restore pre-isr STATUS register contents
SWAPF w_temp,f
SWAPF w_temp,w ; restore pre-isr W register contents
RETFIE
Total = 11-12 TCY (if Timer1 overflow occurred)
ISR @ 0x0008 ; (3-4Tcy), fixed interrupt latency
BRA HIGHINT ; (2Tcy), go to high priority interrupt routine
HIGHINT
BTFSC PIR,TMRIF ; (1Tcy), did a Timer1 overflow occur?
BSF TMR1H,7 ; (1Tcy) Yes, reload for a 1 second overflow
RETFIE FAST
Total = 7-8 TCY (if Timer1 overflow occurred)
ISR @ 0x0018 ; (3-4Tcy), fixed interrupt latency
MOVFF STATUS,STATUS_TEMP ; (2Tcy), save STATUS register
MOVFF WREG,WREG_TEMP ; (2Tcy), save working register, refer to note 1
MOVFF BSR,BSR_TEMP ; (2Tcy), save BSR register, refer to note 1
BTFSS PIR,TMRIF ; (2Tcy), did a Timer1 overflow occur?
BRA EXIT ; No
RELOAD
BSF TMR1H,7 ; (1Tcy) Yes, reload for a 1 second overflow
EXIT
MOVFF BSR_TEMP,BSR ;restore BSR register, refer to note 1
MOVFF WREG_TEMP,WREG ;restore working register, refer to note 1
MOVFF STATUS_TEMP,STATUS ;restore STATUS register
RETFIE
Total = 12-13 TCY (if Timer1 overflow occurred)