Loops and Delays
I am looking for good samples of Loops and Delays for SX Assembly. I have read the pdfs and looked the code. I have a few but I would like to see some explicit examples of the right way to do a Loop and Delay as far as a starting point. Can I get a super simple example?
TIA
JBuma
TIA
JBuma
Comments
Bean.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
I know what I know, don't confuse me with the facts...
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
www.hittconsulting.com
·
A good test is to run this in SxSim, put breakpoints in the NOPs, stop at the first, zero the microsecond time counter, run the enclosed delay routine to the second breakpoint, then see how many microseconds have passed.
These make no attempt to be really accurate but they're pretty good for general purpose delays.
If interrupts are enabled then they'll steal cycles from these, reducing their accuracy even more, but if the ISR is short I've had decent results even in that case.
David
;
device SX28, OSCHS, TURBO, STACKX, OPTIONX
IRC_CAL IRC_FAST
freq 20_000_000
reset start_point
org $F0
bank_assorted = $
t1 ds 1
t2 ds 1
t3 ds 1
t4 ds 1
;
; main program
;
start_point
:here
nop
call @delay1ms
nop
jmp @:here
;
; Jump table
;
org $600
delay1ms jmp @_delay1ms
delay10ms jmp @_delay10ms
delay100ms jmp @_delay100ms
delay1s jmp @_delay1s
;**************************************************************************
; delay functions
_delay1s
bank bank_assorted
mov t4, #100
:l1 call @delay10ms
djnz t4, @:l1
retp
_delay100ms
bank bank_assorted
mov t4, #100
:l1 call @delay1ms
djnz t4, @:l1
retp
_delay10ms
bank bank_assorted
mov t3, #10
:l1 call @delay1ms
djnz t3, @:l1
retp
_delay1ms ; delay 19304 cycles with "15" loop =~ 1 ms @ 20 mHz
bank bank_assorted
mov t2, #15
:l2 mov t1, #0
:l1 djnz t1, @:l1
djnz t2, @:l2
retp
;---the end
Hello Bean, I never used SX/B so I do not know to run the code. Wierd, I know but I have only done the Assembly examples so far.
Take a look at this page:
http://www.sxlist.com/techref/ubicom/lib/flow/delays_sx.htm
Or use the delay code generator
http://www.sxlist.com/techref/piclist/codegen/delay.htm
regards peter