Propeller Manual

Table Of Contents
DIRA, DIRB – Spin Language Reference
Page 106 · Propeller Manual v1.1
The DIRA 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[5..3]~~ 'Set DIRA bits 5 through 3 (P5-P3 to output)
This sets P5, P4 and P3 to outputs; all other bits of DIRA remain in their previous state. Here’s
another example:
DIRA[5..3] := %110 'Set P5 and P4 to output, P3 to input
The above example sets DIRA bits 5, 4 and 3 equal to 1, 1, and 0, respectively, leaving all
other bits in their previous state. Consequently, P5 and P4 are now outputs and P3 is an
input.
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-expression of the previous example.
DIRA[3..5] := %110 'Set P3 and P4 to output, P5 to input
Here, DIRA bits 3, 4 and 5 are set equal to 1, 1, and 0, respectively, making P3 and P4 outputs
and P5 an input.
This is a powerful feature of range-expressions, but if care is not taken, it can also cause
strange, unintentional results.
Normally
DIRA is only written to but it can also be read from to retrieve the current I/O pin
directions. The following assumes
Temp is a variable created elsewhere:
Temp := DIRA[7..4] 'Get direction of P7 through P4
The above sets Temp equal to DIRA bits 7, 6, 5, and 4; i.e., the lower 4 bits of Temp are now
equal to
DIRA7:4 and the other bits of Temp are cleared to zero.