Propeller Manual

Table Of Contents
2: Spin Language Reference – INA, INB
Propeller Manual v1.1 · Page 119
Note because of the “wired-OR” nature of the I/O pins, no electrical contention between cogs
is possible, yet they can all still access I/O pins simultaneously. It is up to the application
developer to ensure that no two cogs cause logical contention on the same I/O pin during run
time. Since all cogs share all I/O pins, a cog could use
INA to read pins it is using as well as
the pins that are in use by one or more other cogs.
Using INA
Read
INA to get the state of I/O pins at that moment. The following example assumes Temp
was created elsewhere.
Temp := INA 'Get state of P0 through P31
This example reads the states of all 32 I/O pins of Port A into Temp.
Using the optional Pin(s) field, the cog can read one I/O pin (one bit) at a time. For example:
Temp := INA[16] 'Get state of P16
The above line reads I/O pin 16 and stores its state (0 or 1) in the lowest bit of Temp; all other
bits of
Temp are cleared.
In Spin, the
INA register supports a special form of expression, called a range-expression,
which allows you to read a group of I/O pins at once, without reading others outside the
specified range. To read multiple, contiguous I/O pins at once, use a range expression (like
x..y) in the Pin(s) field.
Temp := INA[18..15] 'Get states of P18:P15
Here, the lowest four bits of Temp (3, 2, 1, and 0) are set to the states of I/O pins 18, 17, 16,
and 15, respectively, and all other bits of
Temp are cleared to 0.
IMPORTANT: The order of the values in a range-expression affects how it is used. For
example, the following swaps the order of the range from the previous example.
Temp := INA[15..18] 'Get states of P15:P18
Here, Temp bits 3, 2, 1, and 0 are set to the states of I/O pins 15, 16, 17, and 18, respectively.
This is a powerful feature of range-expressions, but if care is not taken it can also cause
strange, unintentional results.