; Set up Timer 2 to generate interrupts every 1 ms. Since we're assuming an instruction
; cycle consumes 1 us, we need to cause an interrupt every 1000 instruction cycles.
; We'll set the prescaler to 4, the PR2 register to 25, and the postscaler to 10. This
; will generate interrupts every 4 x 25 x 10 = 1000 instruction cycles.
; ***********************************************************************************
clrf TMR2 ; Clear Timer2 register
bsf STATUS, RP0 ; Bank1
bsf INTCON,PEIE ; Enable peripheral interrupts
clrf PIE1 ; Mask all peripheral interrupts except
bsf PIE1,TMR2IE ; the timer 2 interrupts.
bcf STATUS, RP0 ; Bank0
clrf PIR1 ; Clear peripheral interrupts Flags
movlw B'01001001' ; Set Postscale = 10, Prescale = 4, Timer 2 = off.
movwf T2CON
bsf STATUS, RP0 ; Bank1
movlw D'25'-1 ; Set the PR2 register for Timer 2 to divide by 25.
movwf PR2
bcf STATUS, RP0 ; Bank0
bsf INTCON,GIE ; Global interrupt enable.
bsf T2CON,TMR2ON ; Timer2 starts to increment