'* Name : Elapsed_INT.bas
; syntax = Handler IntSource, Label, Type, ResetFlag?
DEFINE Elapsed_Handler TMR1_INT, _ClockCount, PBP, yes
Ticks var word ' 1/100th of a second (10ms)
<--- how to change to 1ms ?
BitSave VAR BIT
'''''Goto OverElapsed
<---- ????
' ------------------------------------------------------------------------------
Asm
IF OSC == 4 ; Constants for 100hz interrupt from Timer1
TimerConst = 0D8F7h ; Executed at compile time only
EndIF
If OSC == 8
TimerConst = 0B1E7h
EndIF
If OSC == 10
TimerConst = 09E5Fh
EndIF
If OSC == 16
TimerConst = 063C7h
EndIF
If OSC == 20
TimerConst = 03CB7h
EndIF
; ----------------- ADD TimerConst to TMR1H:TMR1L
ADD2_TIMER macro
CHK?RP T1CON
BCF T1CON,TMR1ON ; Turn off timer
MOVLW LOW(TimerConst) ; 1
ADDWF TMR1L,F ; 1 ; reload timer with correct value
BTFSC STATUS,C ; 1/2
INCF TMR1H,F ; 1
MOVLW HIGH(TimerConst) ; 1
ADDWF TMR1H,F ; 1
endm
; ----------------- ADD TimerConst to TMR1H:TMR1L and restart TIMER1 ----------
RELOAD_TIMER macro
ADD2_TIMER
BSF T1CON,TMR1ON ; 1 ; Turn TIMER1 back on
endm
; ----------------- Load TimerConst into TMR1H:TMR1L --------------------------
LOAD_TIMER macro
MOVE?CT 0, T1CON,0
MOVE?CB 0, TMR1L
MOVE?CB 0, TMR1H
ADD2_TIMER
endm
EndAsm
' ------[ This is the Interrupt Handler ]---------------------------------------
ClockCount:
@ RELOAD_TIMER ; Reload TIMER1
Ticks = Ticks + 1
if Ticks = 65535 then
Ticks = 0
endif
@ INT_RETURN ; Restore context and return from interrupt
'-----====[ END OF TMR1 Interrupt Handler ]====---------------------------------
interrupt:
'
' Restart counting
Tsensor = ticks ; Save the timing between sensor pass through
BitSave = T1CON.0 ; Save TMR1ON bit
@ LOAD_TIMER ; Load TimerConst
T1CON.0 = BitSave ; Restore TMR1ON bit
Ticks = 0
return
Bookmarks