Shop OBEX P1 Docs P2 Docs Learn Events
DIRS and PINS — Parallax Forums

DIRS and PINS

Paul NorsworthyPaul Norsworthy Posts: 2
edited 2012-12-02 14:08 in BASIC Stamp
This may sound like a stupid question, but I'm new at this and a little confused.· In the Parallax Basic Stamp Manual 2.0 it mentions DIRS and PINS.· Are these acronyms?· I am confused as to exactly what these are.· Can someone explain?

Paul

Comments

  • FranklinFranklin Posts: 4,747
    edited 2007-02-03 19:18
    Pins are the pins on the basic stamp that can be inputs or outputs (check the schematics) DIRS sets whether the pin is an input or an output.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - Stephen
  • Paul NorsworthyPaul Norsworthy Posts: 2
    edited 2007-02-03 19:32
    Stephen,



    Does DIRS stand for something or is it a short form?
  • Bruce BatesBruce Bates Posts: 3,045
    edited 2007-02-03 19:43
    Paul -

    There is more than one type of PBASIC Stamp. At the top of the hierarchy, there is the BS-1 (of which there is only one) and the BS-2 series (more than one).

    The BS-1 varient uses DIRS (direction - input or output) and PINS, PIN, P0-P7 (pin ports) and the BS-2 varient uses DIRS (direction - input or output) and INS/OUTS, INx, OUTx for the pin port latch).

    Thus the following serve as a few simple examples:

    To address a pin port:

    BS-1 BS-2

    Pin0 In0

    DIRS works pretty much the same between varients. The BS-2 has 16 pin ports, and the BS-1 has 8 pin ports. The PBASIC Help file has a good deal more information on these statements, as does the PBASIC Reference Manual.

    Regards,

    Bruce Bates

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    <!--StartFragment -->
  • jhoyozajhoyoza Posts: 72
    edited 2007-02-03 23:41
    While you guys are on the subject I have a question. I understand the DIR directive and it’s intent, however I never have had to use it? It appears, most commands will automatically set the pin to either and input or an output on their own. For instance if I use the SERIN or SEROUT command, (and many others) I don’t have to tell the pin whether it is suppose to be an input or an output. It just knows?

    This is a quote from Page 82 • BASIC Stamp Syntax and Reference Manual 2.2

    "When the BASIC Stamp is powered up, or reset, all memory locations are cleared to 0, so all pins are inputs (DIRS = %0000000000000000). Also, if the PBASIC program sets all the I/O pins to outputs (DIRS = %1111111111111111), then they will initially output low, since the output latch (OUTS) is cleared to all zeros upon power-up or reset, as well."

    When looking for an example I did find this program from BASIC Stamp Syntax and Reference Manual 2.2 Page 457


    Demo Program (TOGGLE.bs2)

    ' TOGGLE.bs2
    ' Connect LEDs to pins 0 through 3 as shown in the TOGGLE command descrip-
    ' tion in the manual and run this program. The TOGGLE command will treat
    ' you to a light show. You may also run the demo without LEDs. The Debug
    ' window will show you the states of pins 0 through 3.
    ' {$STAMP BS2}
    ' {$PBASIC 2.5}

    thePin VAR Nib ' pin 0 - 3

    Setup:

    DIRA = %1111 ' make LEDs output, low

    Main:
    DO
    FOR thePin = 0 TO 3 ' loop through pins
    TOGGLE thePin ' toggle current pin
    DEBUG HOME, BIN4 OUTA ' show on Debug
    PAUSE 250 ' short delay
    NEXT
    LOOP ' repeat forever


    Now, if I totally remove the statement => DIRA = %1111 The program will still work just the same?

    Or if I change the statement to read => DIRA = %0000 it also still works just the same?

    To be fair I did find this statement and perhaps this is a good reason of the necessity of the DIRS command?

    Page 84 • BASIC Stamp Syntax and Reference Manual 2.2

    "Note: A direct short and can cause damage to the BASIC Stamp! Do not intentionally connect output pins directly to an external power source or you risk destroying your BASIC Stamp."

    Am I missing something here? Or perhaps I’m just not observant enough?

    Thanks! confused.gif
  • Mike GreenMike Green Posts: 23,101
    edited 2007-02-03 23:51
    The DIRS variable provides another way to affect the input/output status of an I/O pin. You can do most anything with statements like INPUT and LOW/HIGH except change multiple pins with one statement. DIRS and OUTS and their pieces provide for this. The page 84 note is important. That's one reason why I/O pins are initialized to INPUTs on a reset.

    Specifically, you don't need the DIRA assignment for your program
  • UnsoundcodeUnsoundcode Posts: 1,532
    edited 2007-02-04 00:50
    Hi Paul, you must read the section of the Pbasic reference (in your IDE interface) titled Memory and Variables, it explains in detail the use of DIRS,INS and OUTS, the importance of these three registers·is well stated by Mike Green when he said "change multiple pins with one statement", no other Pbasic command can do this and it is something you will surely want to use in future programs.

    Jeff T.
  • jhoyozajhoyoza Posts: 72
    edited 2007-02-04 01:06
    “I see,“ said the blind-man. Well there yeah go, excellent justification! (Aside from pg. 84.)

    I didn’t even think about changing the state of more than one pin at a time. Certainly, I may need to do that someday, and I thank you Mr. Green for your most pragmatic explanation!

    smilewinkgrin.gif
  • CuriousOneCuriousOne Posts: 931
    edited 2012-11-30 02:40
    Why the command DIRS is not mentioned in "basic stamp syntax and reference manual" or in built-in help of basic stamp pc software? Same for INA statement.
  • Mike GreenMike Green Posts: 23,101
    edited 2012-11-30 07:43
    DIRS and INA are indeed mentioned in the Stamp Manual ... with some examples and detailed discussion ... in the section on Stamp Architecture starting on page 81. They're not really commands or statements, but variables ... and can be used anywhere a variable name can be used.
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2012-11-30 09:50
    Does DIRS stand for something or is it a short form?

    DIRection registerS
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2012-11-30 09:57
    jhoyoza wrote:
    Now, if I totally remove the statement => DIRA = %1111 The program will still work just the same?

    Or if I change the statement to read => DIRA = %0000 it also still works just the same?

    To be fair I did find this statement and perhaps this is a good reason of the necessity of the DIRS command?

    Page 84 • BASIC Stamp Syntax and Reference Manual 2.2

    "Note: A direct short and can cause damage to the BASIC Stamp! Do not intentionally connect output pins directly to an external power source or you risk destroying your BASIC Stamp."

    Am I missing something here? Or perhaps I’m just not observant enough?

    If you remove the DIRS = %1111 the program will not run. Unlike other commands such as HIGH, LOW, SERIN, SEROUT, etc. the TOGGLE command does not set the direction register for the I/O pin it is toggling. Because of this without the DIRS statement none of the pins will ever become outputs in that program.

    Changing the statement as you suggested has no affect since that simply makes the pins inputs which they are by default.
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2012-12-02 14:08
    5 years and 10 months later, jhoyoza gets set right.
    We should have buried a time capsule. In Feb. '07, gold was around $650 an ounce, unemployment was under 5%, and gasoline was under $2 a gallon.

    (Sorry, EA, I just couldn't help myself.)
Sign In or Register to comment.