{PBASIC 2.5}
This section discusses the PIN directive available with PBASIC 2.5
(For BASIC Stamp I/O pin definitions and ratings, see Pin Descriptions)
(For BS2px I/O pin commands, see COMPARE and CONFIGPIN.)
With the introduction of PBASIC 2.5 syntax comes the PIN directive. The purpose of the PIN directive is to give an alias to an I/O pin and let the compiler determine whether a given line of code requires a numeric value for the pin, the output bit for that pin, or the input bit for that pin. Using the PIN directive simplifies I/O pin aliasing in sophisticated programs.
Syntax: PIN_Symbol PINPin_Number
PIN_Symbol behaves like a constant:
OUTPUT PIN_Symbol
myArray(PIN_Symbol) = 25
PIN_Symbol behaves like an input variable (INx):
DEBUG BIN PIN_Symbol
IF PIN_Symbol = 1 THEN…
myVariable = PIN_Symbol + 1
PIN_Symbol behaves like an output variable (OUTx):
LOOKUP index, [0, 1, 1, 0, 1], PIN_Symbol
PIN_Symbol = 1
Using the PIN declaration is similar to CON:
' {$PBASIC 2.5} RedLED PIN 0 ' red LED is connected to pin 0 IsOn CON 1 ' LED is active high IsOff CON 0 Setup: OUTPUT RedLED ' same as OUTPUT 0 Main: DO RedLED = IsOn ' same as Out0 = 1 PAUSE 1000 RedLED = IsOff ' same as Out0 = 0 PAUSE 1000 LOOP
Most programs will work like the example above where a given I/O pin will either be an input or an output. There are times, however, when a change in function is required mid program. Prior to PBASIC 2.5, programmers wishing to use named constants were forced to create redundant definitions or complicated modifiers. For example:
' {$PBASIC 2.0} SDA CON 8 ' I2C data I/O SCL CON 9 ' I2C clock output ... I2C_Start: INPUT SDA INPUT SCL LOW SDA Clock_Hold: ' monitor device clock hold IF (INS.LOWBIT(SCL) = 0) THEN Clock_Hold ' <-- tricky modifiers RETURN
With PBASIC 2.5 the tricky modifiers can be eliminated:
' {$PBASIC 2.5} SDA PIN 8 ' I2C data I/O SCL PIN 9 ' I2C clock output ... I2C_Start: INPUT SDA INPUT SCL LOW SDA Clock_Hold: ' monitor device clock hold DO : LOOP WHILE (SCL = 0) ' easier, same as "IN9 = 0" RETURN
The compiler is "smart" and knows how to replace a PIN directive with a constant value, an INS register bit or and OUTS register bit. Note that as in the example above, the programmer is still responsible for setting the DIRS bit of the I/O pin as required by the program.
BASIC Stamp Help Version 2.5.4
Copyright © Parallax Inc.
8/8/2012