;------------------------------------------------------------------------------
BANK0 UDATA
;------------------------------------------------------------------------------
COUNT RES 1 ;COUNT OF INTERRUPTS
COUNT1 RES 1 ;COUNT FOR 1 SECOND TIMER
;------------------------------------------------------------------------------
PROG0 CODE ; program code section
;------------------------------------------------------------------------------
TimerInt ; Interrupt routine
global TimerInt ; Define as global
intsOff bcf INTCON, T0IE ;Disable timer interrupts
;-------------- Insert no new code above here ---------------------------------
CBLOCK 0x30 ; RAM AREA for USE at address 20h
; Variables used in delay routine
counter1ms ; counter for 1ms delay
counter10ms ; counter for 10ms delay
counter100ms ; counter for 100ms delay
counter1000ms ; counter for 1000ms delay
;Variables
ENDC
;*********************************************************************
; 1 ms timer function calls
;*********************************************************************
bcf STATUS, RP0 ;Select Bank 0
bcf STATUS, RP1
;....... 1ms timer counter here.....
clrf TMR0 ;Clear TMR0 and prescaler
banksel TMR0
movlw 0xB2 ;Count=B2
movwf TMR0
;....................................
incf COUNT, f
movlw .10 ;Compare count to 10 decimal
subwf COUNT, W ;Store the result back in
btfss STATUS, C ;Is the result 0, skip if no
goto exittimer
clrf COUNT ;Clear count register
call timer100ms
;**********************************************************************
; 10ms timer function calls
;**********************************************************************
;....... 10ms timer counter here.....
timer10ms
movlw 0x0A
movwf counter10ms
decfsz counter10ms
return
;....................................
incf COUNT1, f
movlw .10 ;Compare count to 100 decimal
subwf COUNT1, W ;Store the result back in
btfss STATUS, C ;Is the result 0, skip if no
goto exittimer
clrf COUNT1
;**********************************************************************
; 100ms timer function calls
;**********************************************************************
;....... 100ms timer counter here.....
timer100ms
movlw 0x64
movwf counter100ms
decfsz counter100ms
return
;....................................
exittimer
movlw .217 ;count 14
movwf TMR0
banksel TMR0
movlw 0xB2 ;Count=B2
movwf TMR0
;-------------- Insert no new code below here ---------------------------------
bcf INTCON, T0IF ;Clear timer overflow flag
; bsf INTCON, T0IE ;Enable interrupts again
return
;----------------------------------------------------------------------------------
;**********************************************************************************
initTimer
Global initTimer
GLOBAL COUNT
clrf COUNT
clrf COUNT1
return
end