Shop OBEX P1 Docs P2 Docs Learn Events
binary # output on i/o — Parallax Forums

binary # output on i/o

zafh15azafh15a Posts: 2
edited 2009-05-24 02:15 in BASIC Stamp
I would like to have a variable expressed as a binary # in parallel on the I/O pins. the variable will be incremented or decremented by user inputs. so I would like the var to be input as a decimal # but then expressed in a 1 byte output on pins

ex:
user inputs··· 1

outputs go
················· 0-0
················· 1-0
··················2-0
··················3-0
··················4-0
················· 5-0
··················6-0
················· 7-1

I can do all of this with lookup table but at the expense of memory. Will the stamp perform this function thru its command set for me somehow.
·

Comments

  • W9GFOW9GFO Posts: 4,010
    edited 2009-05-23 21:23
    Well, without looking in the Basic Stamp manual, here goes.

    VAR BYTE yourNumber

    out0 = yourNumber.bit7
    out1 = yourNUmber.bit6
    out2 = yourNUmber.bit5
    out3 = yourNUmber.bit4
    out4 = yourNUmber.bit3
    out5 = yourNUmber.bit2
    out6 = yourNUmber.bit1
    out7 = yourNUmber.bit0

    Or something like that...

    Rich H
  • UnsoundcodeUnsoundcode Posts: 1,532
    edited 2009-05-24 02:15
    The ideal instruction for this is the OUTS register, the OUTS register (look under Memory and Variables in the PBasic help file) can switch anywhere between 1 and 16 output pins simultaneously with one line of code

    OUTA=3· would result in 0011 on P0 to P3

    Jeff T.
Sign In or Register to comment.