William At MyBlueRoom
New Member
I'd like comments on this simple delay routine. Instead of loops I've used Timer1 with an 8MHz crystal and a 1:8 prescaler. It should increment the LSB every 4us and the TMR1H register every 1.024ms. My math could be off (and my thinking too ) Comments?
Code:
TMRDLY ;*** using TMR1 as a delay for LCD setup call with W
;*** 1.024ms per TMR1H, Delay in ms = 255 - (W * 1.024)
bcf STATUS, RP0 ;B0
clrf TMR1L ;B0 added as per eblc1388 suggestion.
movwf TMR1H ;B0 TMR1H = W (976us)
bcf PIR1, TMR1IF ;B0 clear the interrupt flag
btfss PIR1, TMR1IF ;B0 test TMR1IF for overflow
goto $-1 ; wait for TMR1IF (overflow)
return
Last edited: