Propeller Manual

Table Of Contents
OUTA, OUTB – Spin Language Reference
Note that each cog’s output states are made up of the OR’d states of its internal I/O hardware
(Output Register, Video Generator, etc.) and that is all AND’d with its Direction Register’s
states.
An I/O pin actually outputs low or high, as specified by the cog’s output states, if, and only if,
that pin’s bit in that same cog’s direction register (
DIRA) is high (1). Otherwise, that cog
specifies the pin to be an input and its output state is ignored.
This configuration can easily be described in the following simple rules:
A. A pin outputs low only
if all active cogs that set it to output also set it to low.
B. A pin outputs high if any
active cog sets it to an output and also sets it high.
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 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 OUTA
Set or clear bits in
OUTA to affect the output state of I/O pins as desired. Make sure to also set
the corresponding bits of
DIRA to make that pin an output. For example:
DIRA := %00000100_00110000_00000001_11110000
OUTA := %01000100_00110000_00000001_10010000
The DIRA line above sets the I/O pins 26, 21, 20, 8, 7, 6, 5 and 4 to outputs and the rest to
inputs. The
OUTA line sets I/O pins 30, 26, 21, 20, 8, 7, and 4 to high, the rest to low. The
result is that I/O pins 26, 21, 20, 8, 7, and 4 output high and I/O pins 6 and 5 output low. I/O
pin 30 is set to an input direction (according to
DIRA) so the high in bit 30 of OUTA is ignored
and the pin remains an input according to this cog.
Using the optional Pin(s) field, and the post-clear (
~) and post-set (~~) unary operators, the
cog can affect one I/O pin (one bit) at a time. The Pin(s) field treats the I/O pin registers as
an array of 32 bits. For example:
DIRA[10]~~ 'Set P10 to output
OUTA[10]~ 'Make P10 low
OUTA[10]~~ 'Make P10 high
Page 176 · Propeller Manual v1.1