Propeller Manual

Table Of Contents
2: Spin Language Reference – OUTA, OUTB
Propeller Manual v1.1 · Page 177
The first line in the code above sets I/O pin 10 to output. The second line clears P10’s output
latch bit, making P10 output low (ground). The third line sets P10’s output latch bit, making
P10 output high (VDD).
In Spin, the OUTA register supports a special form of expression, called a range-expression,
which allows you to affect a group of I/O pins at once, without affecting others outside the
specified range. To affect multiple, contiguous I/O pins at once, use a range expression (like
x..y) in the Pin(s) field.
DIRA[12..8]~~ 'Set DIRA12:8 (P12-P8 to output)
OUTA[12..8] := %11001 'Set P12:8 to 1, 1, 0, 0, and 1
The first line, “DIRA,” sets P12, P11, P10, P9 and P8 to outputs; all other pins remain in
their previous state. The second line, “
OUTA,” sets P12, P11, and P8 to output high, and P10
and P9 to output low.
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.
DIRA[8..12]~~ 'Set DIRA8:12 (P8-P12 to output)
OUTA[8..12] := %11001 'Set OUTA8:12 to 1, 1, 0, 0, and 1
Here, DIRA bits 8 through 12 are set to high (like before) but OUTA bits 8, 9, 10, 11 and 12 are
set equal to 1, 1, 0, 0, and 1, respectively, making P8, P9 and P12 output high and P10 and
P11 output low.
This is a powerful feature of range-expressions, but if care is not taken it can also cause
strange, unintentional results.
Normally
OUTA is only written to but it can also be read from to retrieve the current I/O pin
output latch states. This is ONLY the cog’s output latch states, not necessarily the actual
output states of the Propeller chip’s I/O pins, as they can be further affected by other cogs or
even this cog’s other I/O hardware (Video Generator, Count A, etc.). The following assumes
Temp is a variable created elsewhere:
Temp := OUTA[15..13] 'Get output latch state of P15 to P13
The above sets Temp equal to OUTA bits 15, 14, and 13; i.e.: the lower 3 bits of Temp are now
equal to
OUTA15:13 and the other bits of Temp are cleared to zero.