cblock 0x000
delayHi
endc
;==================================================================
; K8LH DelayCy() subsystem macro generates four instructions =
;==================================================================
radix dec
clock equ 4 ; 4, 8, 12, 16, 20 (MHz), etc.
usecs equ clock/4 ; cycles/microsecond multiplier
msecs equ clock/4*1000 ; cycles/millisecond multiplier
DelayCy macro delay ; 11..327690 cycle range
movlw high((delay-11)/5)+1
movwf delayhi
movlw low ((delay-11)/5)
call uDelay-(((delay-11)%5)*2)
endm
;******************************************************************
; example code for simulation testing *
;******************************************************************
org 0x000
SimTest
DelayCy(200*usecs) ; <- put simulator PC here
goto $ ; <- put simulator break point here
;******************************************************************
; K8LH DelayCy() 16-bit uDelay (11..327690 cycle) subroutine *
;******************************************************************
nop ; entry for (delay-11)%5 == 4
nop ; entry for (delay-11)%5 == 3
nop ; entry for (delay-11)%5 == 2
nop ; entry for (delay-11)%5 == 1
uDelay addlw -1 ; subtract 5 cycle loop time
skpc ; borrow? no, skip, else
decfsz delayhi,F ; done? yes, skip, else
goto uDelay ; do another loop
return ;
;******************************************************************
end