Shop OBEX P1 Docs P2 Docs Learn Events
How to output one bit to a pin? — Parallax Forums

How to output one bit to a pin?

Thomas TaylorThomas Taylor Posts: 27
edited 2012-11-30 15:49 in Propeller 1
How do you take the LSB in a byte and outa[x] to a particular pin? I’ve thought of a few ways to use logic operators that may accomplish this goal, but each of these seemed too cumbersome. I may be lost in the woods and missing the obvious. Thanks in advance for some guidance. Tom

Comments

  • average joeaverage joe Posts: 795
    edited 2012-11-30 14:53
    I would do something like:
    CON
    pin = 0       'pin number 
    
    VAR
    byte namebyte
    
    PUB
    ..
    ..
    outa[pin] := namebyte & $0000_0001
    

    This is assuming you're working in SPIN. If PASM let me know and I will post example for that too!
  • MagIO2MagIO2 Posts: 2,243
    edited 2012-11-30 14:53
    I think this should be enough
    outa[x]:= variable

    SPIN takes care of using the LSB. This is because the pin in [] can also be a range, so outa assignment already has work with a flexible number of bits and has to mask out the bits that are not needed.
  • average joeaverage joe Posts: 795
    edited 2012-11-30 14:55
    MagIO2 wrote: »
    I think this should be enough
    outa[x]:= variable

    You're probably right about that! I've spent too much time in PASM lately...
  • Thomas TaylorThomas Taylor Posts: 27
    edited 2012-11-30 15:49
    Thanks guys!
    outa[x]:= variable works just fine.
    Also thanks for the explanation, MagIO2.
    I must have missed that point in the PEK Labs: Fundamentals book.
Sign In or Register to comment.