Shop OBEX P1 Docs P2 Docs Learn Events
Statement equivelents — Parallax Forums

Statement equivelents

kingnebkingneb Posts: 65
edited 2005-10-19 02:44 in BASIC Stamp
In the BASIC stamp PBasic language what are the equivilent statements to these in SX basic:

tris_b = %00000000 'portb all output

rb = 255 'make all outputs high

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
All my exes live in Texas


Oh yeah, all my exes are six feet under the ground!!!

One was a lineman who violated the one hand rule.

The·second put his tongue on 10 car batteries wired in series.

The third was involved in a tesla coil experiment gone bad.

Comments

  • NewzedNewzed Posts: 2,503
    edited 2005-10-17 22:07
    Trisb refers to Ports B.0 thru B.7.· The Stamp does not have these ports.
    The closest you could come in PBasic would be OUTL or OUTH, which covers Stamp Pins 0 to 7 and 8 to 15.


    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Sid Weaver
    Do you have a Stamp Tester yet?
    http://hometown.aol.com/newzed/index.html

    ·
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-10-17 22:16
    On BASIC Stamps that use the SX, the B port is connected to P0..P7.· So, these SX/B statements:

    · TRIS_B = %00000000
    ··RB = 255

    ... translate to PBASIC as:

    · DIRL = %11111111
    · OUTL = 255

    What you'll notice is that the BASIC Stamp uses 1 to set a bit as an output, where the SX uses 0.· Why?· Well, this is an old convention where all BASIC Stamp RAM (and I/O is mapped into RAM) is cleared to zero.· Since we want reset the pins to inputs, that's what happens.· What you can correctly infer from this is that DIRL and OUTL are actually shadow registers, and the bits in DIRL are inverted before writing to the TRIS_B register.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • Bruce BatesBruce Bates Posts: 3,045
    edited 2005-10-17 22:29
    kingneb -

    In PBASIC, you want to look at the following commands:

    /code

    DIRS = Direction register - 16 ports,· or 2 x 8, or·4 x 4;·0 = Input,·1·= Output
    DIRS,·DIRL, DIRH, DIRA, DIRB, DIRC, DIRD
    ·ALL···Bot 8· Top 8·· 0-3··· 4-7··· 8-11·· 12-16
    · 16

    INS = Input pin port register - 16 ports, or 2 x 8, or 4 x 4
    INS,· INL,··· INH,·· INA,· INB,· INC,·· IND
    ·ALL··Bot 8· Top 8· 0-3·· 4-7·· 8-11· 12-16
    · 16

    OUTS = Output pin port register - 16 ports, or 2 x 8, or 4 x 4
    OUTS, OUTL, OUTH, OUTA, OUTB, OUTC, OUTD
    ·ALL··· Bot 8·· Top 8··· 0-3··· 4-7··· 8-11·· 12-16
    · 16

    code/

    If one were to arbitrarily label Pin ports 0-7 as Port B, and Pin port 8-15 as Port A, you could effect the same settings as on the SX with the following PBASIC commands:

    DIRL· = $00
    OUTL = $FF

    Regards,

    Bruce Bates



    Post Edited (Bruce Bates) : 10/19/2005 2:50:14 AM GMT
  • kingnebkingneb Posts: 65
    edited 2005-10-19 00:37
    Will this statement make pins 0 to 7 output?

    DIRH = %11111111

    Will this statement make pins 14 and 15 inputs?

    DIRL = %11111100

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    All my exes live in Texas


    Oh yeah, all my exes are six feet under the ground!!!

    One was a lineman who violated the one hand rule.

    The·second put his tongue on 10 car batteries wired in series.

    The third was involved in a tesla coil experiment gone bad.
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-10-19 01:35
    You'll find the PBASIC manual (or help file) very clear on this point: To make a pin an output you must set the associated DIRS bit to 1. The BASIC Stamp clears all RAM to zeros (and IO space is mapped into RAM) so that makes all pins inputs after reset.

    Also, binary values are listed: MSB...LSB.· To make P0 - P7 outputs you would do this:

    · DIRL = %11111111

    Now, you don't have to set P14 and P15 to inputs at the beginning of the program, because that's their default state.·

    Bruce has a typo in his post regarding the bits in the BASIC Stamp DIRS register.· In the BASIC Stamp, 1 = output, 0 = input -- this is just the opposite of program the SX in SX/B or assembly language.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax

    Post Edited (Jon Williams (Parallax)) : 10/19/2005 2:47:15 AM GMT
  • Fe2o3FishFe2o3Fish Posts: 170
    edited 2005-10-19 02:34
    Uh.... Jon, wouldn't that be

    DIRH = %11000000
    



    for pins 14 & 15 to be used as output, not DIRL?
    And

    DIRH = %00111111
    



    if pins 14 & 15 are to be used for inputs?

    Well, at least according to the Help file, if I read it right, it does.
    I think Bruce had it right. Just being a pick nitter again. smile.gif

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    -Rusty-
    --
    Rusty Haddock = KD4WLZ = rusty@fe2o3.lonestar.org
    **Out yonder in the Van Alstyne (TX) Metropolitan Area**
    Microsoft is to software what McDonalds is to gourmet cooking
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-10-19 02:44
    Whoops, indeed it would be -- post fixed. Thanks, Rusty, it's been a long day....

    Bruce's post incorrectly states that for the DIRS register, 1 = input and 0 = output. This is NOT the case with the BASIC Stamp.

    From the help file:

    To summarize: DIRS determines whether a pin's state is set by external circuitry (input, 0) or by the state of OUTS (output, 1). INS always matches the actual states of the I/O pins, whether they are inputs or outputs. OUTS holds bits that will only appear on pins whose DIRS bits are set to output.

    (Emphasis mine)

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax

    Post Edited (Jon Williams (Parallax)) : 10/19/2005 2:52:15 AM GMT
Sign In or Register to comment.