Propeller Manual

Table Of Contents
2: Spin Language Reference – DIRA, DIRB
This configuration can easily be described in the following simple rules:
A. A pin is an input only
of no active cog sets it to an output.
B. A pin is an output if any
active cog sets it to an output.
If a cog is disabled, its direction register is treated as if were cleared to 0, causing it to exert
no influence on I/O pin directions and states.
Note that 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.
Using DIRA
Set or clear bits in
DIRA to affect the direction of I/O pins as desired. For example:
DIRA := %00000000_00000000_10110000_11110011
The above code sets the entire DIRA register (all 32 bits at once) to a value that makes I/O pins
15, 13, 12, 7, 6, 5, 4, 1 and 0 to outputs and the rest to inputs.
Using the post-clear (
~) and post-set (~~) unary operators, the cog can set all I/O pins to
inputs, or outputs, respectively; it’s not usually desirable to set all I/O pins to outputs,
however. For example:
DIRA~ 'Clear DIRA register (all I/Os are inputs)
—and—
DIRA~~ 'Set DIRA register (all I/Os are outputs)
The first example above clears the entire DIRA register (all 32 bits at once) to zero; all I/Os P0
through P31 to inputs. The second example above sets the entire
DIRA register (all 32 bits at
once) to ones; all I/Os P0 through P31 to outputs.
To affect only one I/O pin (one bit), include the optional Pin(s) field. This treats the
DIRA
register as an array of 32 bits.
DIRA[5]~~ 'Set DIRA bit 5 (P5 to output)
This sets P5 to an output. All other bits of DIRA (and thus all other corresponding I/O pins)
remain in their previous state.
Propeller Manual v1.1 · Page 105