; Time adjustment is calculated as a function of: ; rollover - # clock cycles to rollover ; required - # clock cycles desired ; read|modify|write - time allowance to read counter, modify it to the ; desired count, and write counter back ; 2 - two cycles are lost to resynchronization upon counter write back ; time_adj = rollover - required + read|modify|write + 2 ;;; time_adj equ d'65536'-d'25000'+d'12'+2 ten_ms btfss INTCON,TMR0IF ;test timer0 rollover flag bra ten_ms ;... polling loop movff TMR0L,tmr0l_c ;read 16 bit counter movff TMR0H,tmr0h_c ;get buffered high half movlw low time_adj ;add time adjustment addwf tmr0l_c,F movlw high time_adj addwfc tmr0h_c,F movff tmr0h_c,TMR0H ;pre-load high half first movff tmr0l_c,TMR0L ;write the 16 bit counter bcf INTCON,TMR0IF ;clear timer0 rollover flag return ;and return