EPAIII
Member
I am searching the past posts for a way to output a Word variable as a series of bits on one pin. I came across this post from 2007 that seems to be doing that, but I have a question about how it works. First the quote:
Hippy, on 10/25/2005 said;
"I haven't tested it, but the fastest way to clock 8 bits out msb first ( removing the FOR-NEXT overhead ), could be to put it in "b0 ( MSB of w0 ) and set b0 (LSB of w0 ) to $FF. As w0=w0*2 operates the LSB is eventually cleared ...
"
"- b1 = $A5 ' Data to send
"- b0 = $FF
"-
"- BitLoop:
"- pinX = bit15
"- w0 = w0*2
"- IF b0 <> 0 THEN BitLoop
"
"To shift 16 bits out, w0 and another word variable can be used ...
"
"- w0 = $A593 ' Data to send
"- w1 = $FFFF
"-
"- BitLoop:
"- pinX = bit15
"- w0 = w0*2
"- w1 = w1*2
"- IF w1 <> 0 THEN BitLoop
"
"No PULSOUT's shown in the above. The code can be modified to do lsb first by some simple changes. It should also be possible "to send an arbitrary number of bits by selecting the right bitX variable and setting the $FF/$FFFF to have some zero bits."
I am interested in the first version for a Word sized output. I can understand it up to the last line, "IF b0 <> 0 THEN BitLoop". It is obviously testing the bo Word, which I would assume would become zero when the last or eighth bit has been sent. But just how is that being done? What are < and >? And how do they work in the IF ... THEN statement?
From the rest of the conversation, at that time, this method was apparently suggested to avoid using a FOR ... NEXT loop which seems to be the obvious way to do this. Just loop through the lines of code eight times for each bit in the Word. Is a FOR ... NEXT loop particularly slow or does it consume a lot of memory? Why would I want to avoid it? Or is this completely obsolete? Is there a better suggestion now? I would want a routing that is first fast and then as compact in terms of memory usage as possible.
Hippy, on 10/25/2005 said;
"I haven't tested it, but the fastest way to clock 8 bits out msb first ( removing the FOR-NEXT overhead ), could be to put it in "b0 ( MSB of w0 ) and set b0 (LSB of w0 ) to $FF. As w0=w0*2 operates the LSB is eventually cleared ...
"
"- b1 = $A5 ' Data to send
"- b0 = $FF
"-
"- BitLoop:
"- pinX = bit15
"- w0 = w0*2
"- IF b0 <> 0 THEN BitLoop
"
"To shift 16 bits out, w0 and another word variable can be used ...
"
"- w0 = $A593 ' Data to send
"- w1 = $FFFF
"-
"- BitLoop:
"- pinX = bit15
"- w0 = w0*2
"- w1 = w1*2
"- IF w1 <> 0 THEN BitLoop
"
"No PULSOUT's shown in the above. The code can be modified to do lsb first by some simple changes. It should also be possible "to send an arbitrary number of bits by selecting the right bitX variable and setting the $FF/$FFFF to have some zero bits."
I am interested in the first version for a Word sized output. I can understand it up to the last line, "IF b0 <> 0 THEN BitLoop". It is obviously testing the bo Word, which I would assume would become zero when the last or eighth bit has been sent. But just how is that being done? What are < and >? And how do they work in the IF ... THEN statement?
From the rest of the conversation, at that time, this method was apparently suggested to avoid using a FOR ... NEXT loop which seems to be the obvious way to do this. Just loop through the lines of code eight times for each bit in the Word. Is a FOR ... NEXT loop particularly slow or does it consume a lot of memory? Why would I want to avoid it? Or is this completely obsolete? Is there a better suggestion now? I would want a routing that is first fast and then as compact in terms of memory usage as possible.