DIRS and PINS
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
Paul
Comments
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- Stephen
Does DIRS stand for something or is it a short form?
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 -->
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!
Specifically, you don't need the DIRA assignment for your program
Jeff T.
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!
DIRection registerS
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.
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.)