PDA

View Full Version : DIRS and PINS



Paul Norsworthy
02-04-2007, 02:16 AM
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

Franklin
02-04-2007, 02:18 AM
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 Norsworthy
02-04-2007, 02:32 AM
Stephen,



Does DIRS stand for something or is it a short form?

Bruce Bates
02-04-2007, 02:43 AM
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 -->

jhoyoza
02-04-2007, 06:41 AM
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! http://forums.parallax.com/images/smilies/confused.gif

Mike Green
02-04-2007, 06:51 AM
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

Unsoundcode
02-04-2007, 07:50 AM
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.

jhoyoza
02-04-2007, 08:06 AM
“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!

http://forums.parallax.com/images/smilies/smilewinkgrin.gif

CuriousOne
11-30-2012, 09:40 AM
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 Green
11-30-2012, 02:43 PM
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 Savage
11-30-2012, 04:50 PM
Does DIRS stand for something or is it a short form?

DIRection registerS

Chris Savage
11-30-2012, 04:57 PM
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.

PJ Allen
12-02-2012, 09:08 PM
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 (http://www.usagold.com/reference/prices/2007.html), unemployment was under 5% (http://data.bls.gov/timeseries/LNS14000000), and gasoline was under $2 a gallon (http://usatoday30.usatoday.com/money/industries/energy/2008-11-03-gas-oil-prices_N.htm).

(Sorry, EA, I just couldn't help myself.)