BlackOps
Full Member level 5
- Joined
- Jan 1, 2005
- Messages
- 279
- Helped
- 14
- Reputation
- 28
- Reaction score
- 3
- Trophy points
- 1,298
- Location
- AZERBAIJAN
- Activity points
- 2,496
mikrobasic retfie
Hello, i think most of you probably saw this webpage:
https://romanblack.com/one_sec.htm
it is about how to make exactly 1 second delay on PICs using interrupts.
but my problem is i absolutely dont understand the heart of this algorithm.
here is a fragment of code:
he declares three variables, and assigns them values:
(in DEcimal) bres_hi = 15, bres_mid = 66 + 1, bres_lo = 64
this is done in setup routine which runs only once:
and this code, which contains counting algorithm for one second runs in the interrupt handler:
movf bres_mid,1
btfsc STATUS,2
decf bres_hi,f
decfsz bres_mid,f
goto int_exit
movf bres_hi,1
btfss STATUS,2
goto int_exit
movlw 0x0F
movwf bres_hi
movlw 0x42 +1
movwf bres_mid
movlw 0x40
addwf bres_lo,f
btfss STATUS,0
incf bres_mid,f
;MY EVENT WHICH OCCURS EVERY ONE SECOND
int_exit
bcf INTCON,T0IF
movf status_temp,w
movwf STATUS
swapf w_temp,f
swapf w_temp,w
retfie
i dont get how does he get one second event from those numbers in decimal, 15, 66+1 and 64?
can anyone explain me this with formula?
and for example show me how is it possible to remake this code work for every...say....2....5....10 seconds?
i'd appreciate your help!
thanks in advance
Hello, i think most of you probably saw this webpage:
https://romanblack.com/one_sec.htm
it is about how to make exactly 1 second delay on PICs using interrupts.
but my problem is i absolutely dont understand the heart of this algorithm.
here is a fragment of code:
he declares three variables, and assigns them values:
(in DEcimal) bres_hi = 15, bres_mid = 66 + 1, bres_lo = 64
this is done in setup routine which runs only once:
Code:
movlw 0x0F
movwf bres_hi
movlw 0x42 +1
movwf bres_mid
movlw 0x40
movwf bres_lo
and this code, which contains counting algorithm for one second runs in the interrupt handler:
movf bres_mid,1
btfsc STATUS,2
decf bres_hi,f
decfsz bres_mid,f
goto int_exit
movf bres_hi,1
btfss STATUS,2
goto int_exit
movlw 0x0F
movwf bres_hi
movlw 0x42 +1
movwf bres_mid
movlw 0x40
addwf bres_lo,f
btfss STATUS,0
incf bres_mid,f
;MY EVENT WHICH OCCURS EVERY ONE SECOND
int_exit
bcf INTCON,T0IF
movf status_temp,w
movwf STATUS
swapf w_temp,f
swapf w_temp,w
retfie
i dont get how does he get one second event from those numbers in decimal, 15, 66+1 and 64?
can anyone explain me this with formula?
and for example show me how is it possible to remake this code work for every...say....2....5....10 seconds?
i'd appreciate your help!
thanks in advance