Question about djnz
Trying to get this chuck of code to work, the idea is the aDAT pin cycles twice, then the aSER pin cycles 24 times then waits for the aDAT pin to cycle again.
There is more code before the posted chunk that works fine.
Any help would be appreciated.
:loop1 mov bitcount, #24 waitpeq aDAT, aDAT waitpne aDAT, aDAT waitpeq aDAT, aDAT waitpne aDAT, aDAT :loop2 xor outa, aSER waitcnt cnt, delay xor outa, aSER waitcnt cnt, delay djnz bitcount, #:loop2 jmp #:loop1 waitpeq $, #0 delay long 200
There is more code before the posted chunk that works fine.
Any help would be appreciated.
Comments
So, to wait 10 cycles, you do this:
If you wanted to wait 10 cycles, then run some code, then wait for exactly 100 cycles from when you started, you do this:
So I think in your case, you want:
It's also worth noting that the delay "begins" from the moment you read the previous count value. In my code, I'm adding the counter after setting the delay time, so the delay is counting from the instruction where the add takes place.
Some people prefer this:
That's a rather odd example don't you think?
Why do you say that?
@SSkalko: What about this: It makes sure that your initial waitcnt target is one which can be reached in a reasonable time frame, i.e. is known.
Need some in-line comments here, this is as twisted as the
As for waitcnt, maybe you feel more comfortable with this version: The #9 makes sure that an immediately following waitcnt just falls through (6 cycles). Any other value (greater 8) will do. I prefer it this way. Using cnt in the dst slot refers to its shadow register (i.e. is as good as temp).
I was just wondering how you got the posted lines of code to show in red.
Please walk me through this. Where does "5{14} + 5" come from?
(@Publison: Thanks! How did you know?)