Hello,
For those interested, the following code is that associated with the ROM based DELNUS sub-routine. It is simple enough to place within your own code, if required (when you don't know the address of the ROM version).
* NAME: _DELNUS
* PURPOSE: Delay N us
* ENTRY CONDITIONS:
* X = Delay(us) / 12
* ACC = CPUbus(MHz) * 4 (= oscillator frequency)
* SIZE: 10 BYTES
* STACK USED (INCLUDING CALL): 3 bytes
* REMARKS:
* fop >= 1 MHz, minimum delay = 12 us (+5 cycles)
************************************************************
_DELNUS: DECA ; 1 cycle
NXTX: PSHA ; 2
DECA ; 1
DECA ; 1
DBNZA * ; 3 Execute ACC-3 times
PULA ; 2
DBNZX NXTX ; 3 Loop X times - X*(3*(ACC-3)+ 9)
RTS ; 4
; Total delay = X*(3*ACC-9+9)+ 5 + Call
; = 3*X*ACC + 5 + Call
The interesting point about the routine is its ability to allow for different bus rates by simply setting the value in ACC - and this consumes a total of only 10 bytes. The maximum possible delay is a little over 3 ms.
Regards,
Mac
Message Edited by bigmac on
2007-05-12 01:08 PM