cblock 0x70
delayhi ; DelayCy() sub-system timing variable
endc
;==================================================================
; K8LH DelayCy() subsystem macro generates four instructions =
;==================================================================
radix dec
clock equ 32 ; 4, 8, 12, 16, 20 (MHz), etc.
usecs equ clock/4 ; cycles/microsecond multiplier
msecs equ usecs*1000 ; cycles/millisecond multiplier
dloop equ 31 ; loop size, 5 to ??? cycles
;
; -- loop -- -- delay range -- -- memory overhead ----------
; 5-cyc loop, 11..327690 cycles, 9 words (+4 each macro call)
; 6-cyc loop, 11..393226 cycles, 10 words (+4 each macro call)
; 7-cyc loop, 11..458762 cycles, 11 words (+4 each macro call)
; 8-cyc loop, 11..524298 cycles, 12 words (+4 each macro call)
; 9-cyc loop, 11..589834 cycles, 13 words (+4 each macro call)
;
DelayCy macro cycles ; range, see above
if (cycles<11)|(cycles>(dloop*65536+10))
error " DelayCy range error "
else
movlw high((cycles-11)/dloop)+1
movwf delayhi
movlw low ((cycles-11)/dloop)
call uLoop-((cycles-11)%dloop)
endif
endm
;******************************************************************
; example code for simulation testing *
;******************************************************************
org 0x000
SimTest
DelayCy(200*msecs) ; <- put simulator PC here
goto $ ; <- put simulator break point here
;******************************************************************
; K8LH DelayCy() subsystem 16-bit 'uLoop' timing subroutine *
;******************************************************************
a = dloop-1
while a > 0
nop ; (cycles-11)%dloop entry points |B0
a -= 1
endw
uLoop addlw -1 ; subtract 'dloop' loop time |B0
skpc ; borrow? no, skip, else |B0
decfsz delayhi,F ; done? yes, skip, else |B0
goto uLoop-dloop+5 ; do another loop |B0
return ; |B0
;******************************************************************
end