;******************************************************************
; *
; DelayUS(16..262159), 4 MHz clock Mike McLaren, K8LH, Jun'07 *
; *
; requires the use of constant operands known at assembly time! *
; *
; 12 words, 1 RAM variable, 14-bit core *
; ^^^^^^^^^^^ *
; the macro produces 4 instructions; *
; *
DelayUS macro delay ; parameter range 16..262159
movlw high((delay-16)/4)+1
movwf TMRH
movlw low ((delay-16)/4)
call DelayLo-(delay%4)
endm
; *
; example code for simulation testing; *
; *
SimTest DelayUS(262159) ; delay 'n' usecs
nop ; put simulator break point here
; *
;******************************************************************
; *
Delay.16F
nop ; entry point for delay%4 == 3
nop ; entry point for delay%4 == 2
nop ; entry point for delay%4 == 1
DelayLo addlw -1 ; subtract 4 cycle loop time
skpnc ; borrow? yes, skip, else
goto DelayLo ; do another loop
nop ;
DelayHi addlw -1 ; subtract 4 cycle loop time
decfsz TMRH,F ; done? yes, skip, else
goto DelayLo ; do another loop
goto $+1 ;
return ;
;******************************************************************