;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; ~
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
radix dec
go1000
movlw high(1000)+1 ; 1-second gate |00
movwf r3 ; |00
movlw low(1000) ; |00
movwf r2 ; |00
goto prep ; branch unconditionally |00
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; ~
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
radix dec
go0001
movlw high(1)+1 ; 1-msec gate |00
movwf r3 ; |00
movlw low(1) ; |00
movwf r2 ; |00
prep
clrf TMR0 ; clear TMR0 and prescaler |00
clrf acc0 ; clear the 32-bit counter |00
clrf acc1 ; " |00
clrf acc2 ; " |00
clrf acc3 ; " |00
bcf STATUS,IRP ; set FSR/INDF for bank 0-1 |00
movlw TRISA ; setup indirect access to TRISA |00
movwf FSR ; for T0CKI (RA2) data direction |00
bsf INDF,TRISA2 ; TRISA2 = 1, RA2 gate "on" |00 (gate on)
gate
inDelay(1*msecs-14) ; 1-msec minus 14 (loop) cycles |00
movlw 1<<TMR0IF ; check TMR0 overflow each loop |00 ( 1)
andwf INTCON,W ; " |00 ( 2)
skpz ; TMR0 overflow? no, skip, else |00 ( 3)
bcf INTCON,TMR0IF ; clear TMR0IF flag |00 ( 4)
skpz ; TMR0 overflow? no, skip, else |00 ( 5)
movlw 1 ; bump the overflow counters |00 ( 6)
addwf acc2,F ; add 0 or 1 |00 ( 7)
skpnz ; zero result? no, skip, else |00 ( 8)
addwf acc3,F ; add 0 or 1 |00 ( 9)
decf r2,F ; decrement loop counter |00 (10)
skpnz ; " |00 (11)
decfsz r3,F ; done? yes, skip, else |00 (12)
goto gate ; do another 1-msec loop |00 (14)(13)
bcf INDF,TRISA2 ; TRISA2 = 0, RA2 gate "off" |00 (gate off)
;
; perform a final check for TMR0 overflow
;
movlw 0 ; |00
btfsc INTCON,TMR0IF ; TMR0 overflow? no, skip, else |00
movlw 1 ; bump the overflow counters |00
addwf acc2,F ; add 0 or 1 |00
skpnz ; zero? no, skip, else |00
addwf acc3,F ; add 0 or 1 |00
bcf INTCON,TMR0IF ; clear TMR0IF unconditionally |00
;
; transfer TMR0 and prescaler values into 32-bit count & return
;
movf TMR0,W ; |00
movwf acc1 ; xfer TMR0 value into count |00
flush bcf PORTA,RA2 ; clock the T0CKI pin |00
bsf PORTA,RA2 ; " |00
decf acc0,F ; decrement counter LSB |00
movf TMR0,W ; prescaler overflow into TMR0? |00
xorwf acc1,W ; " |00
bz flush ; no, loop (clock it again) |00
return ; |00
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~