How can someone Byte a Pin?
Erlend
Posts: 612
I cannot find anything about this functionality in the manual. In this code snippet:
-or is there some other black art going on?
Erlend
PRI writeByte( cmd ) | i dira[io]~~ 'set to output repeat i from 0 to 7 'for every bit in the byte outa[io] := cmd ' outa[clk]~~ cmd >>= 1 outa[clk]~I can see that outa[io] is assigned the value of cmd - but - the value of cmd is not 1 or 0, but some number. What I gather from the right-shifting is that only the lsb is used by the outa. Correct? So for each loop the rightmost bit is what controls the output?
-or is there some other black art going on?
Erlend
Comments
You've got it right.
The variable "io" represents a single pin number. If you wanted to control 8 pins (let's say 8 through 15) at once with the "cmd" variable you'd do this.
As in your earlier example, only the least significant bit(s) of cmd are used. Pin 8 would have the LSB on it. You could have the LSB on pin 15 if you use:
The example you gave is a common way of clocking bits out in I2C or SPI protocols.