Shop OBEX P1 Docs P2 Docs Learn Events
How can someone Byte a Pin? — Parallax Forums

How can someone Byte a Pin?

ErlendErlend Posts: 612
edited 2013-04-23 11:34 in Propeller 1
I cannot find anything about this functionality in the manual. In this code snippet:
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

  • Duane DegnDuane Degn Posts: 10,588
    edited 2013-04-23 11:34
    Erlend wrote: »
    IWhat 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?

    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.
    outa[15..8] := cmd
    

    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:
    outa[8..15] := cmd
    

    The example you gave is a common way of clocking bits out in I2C or SPI protocols.
Sign In or Register to comment.