delayhi equ 0x20
;******************************************************************
; 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)
endm
;******************************************************************
; example code for simulation testing *
;******************************************************************
org 0x000
radix dec
SimTest
DelayCy(12*msecs) ; <- put simulator PC here
goto $ ; <- put simulator break point here
;******************************************************************
; K8LH DelayCy() subsystem 16-bit uDelay(11..327690 cycle) sub- *
; routine uses Mike Bond's 4-word 5-cycle 16-bit timing loop *
; *
; 9 words, 1 RAM variable, 14-bit core *
;******************************************************************
nop ; entry for (delay-11)%5 == 4 |B0
nop ; entry for (delay-11)%5 == 3 |B0
nop ; entry for (delay-11)%5 == 2 |B0
nop ; entry for (delay-11)%5 == 1 |B0
uDelay addlw -1 ; subtract 5 cycle loop time |B0
skpc ; borrow? no, skip, else |B0
decfsz delayhi,F ; done? yes, skip, else |B0
goto uDelay ; do another loop |B0
return ; |B0
;******************************************************************