ColorPAL documentation

© Parallax, Inc. • ColorPAL (2009.06.15) Page 7 of 12
' {$STAMP BS2}
' {$PBASIC 2.5}
sio PIN 15
baud VAR Word
pwidth VAR Word
i VAR Byte
PAUSE 100
baud = $ffff
FOR i = 0 TO 255
PULSIN sio, 0, pwidth
baud = baud MAX pwidth
NEXT
baud = baud << 1 - 20 | 32768
+nn
Address Networked ColorPALs
While in Direct mode (and only then) a plus sign (+) followed by two hexadecimal digits will be accepted
as a “network” address. Multiple ColorPALs can be paralleled and addressed individually in Direct mode.
Each ColorPAL can be assigned an eight-bit unit number, which is saved at EEPROM location 3F and
loaded when the ColorPAL resets. When a non-zero network address is received in Direct mode via the +
command, it is ANDed with the ColorPAL’s unit number. If the result is zero, the ColorPAL will ignore
further direct commands until either a 00 address or one which, when ANDed to its unit number, yields a
non-zero value. The 00 address can thus be thought of as a broadcast address, to which all ColorPALs
will respond. A new, unprogrammed ColorPAL comes with a unit number of 00, which means it will
respond
only
to address 00.
To change a ColorPAL’s unit number, simply create a one-instruction program, with the instruction being
one that takes a number (i.e. p or t), and save it to EEPROM location 3E. That will place the number in
location 3F and will be effective
after the next and subsequent resets
. Here’s an example:
SEROUT sio, baud, ["= p03 #3E"]
This programs the ColorPAL to have unit number 03 (%00000011), which means it will respond to any
address with one or both of its least-significant bits set.
IMPORTANT: Network addressing works
only
in Direct mode. It cannot be used to select which of two
or more ColorPALs already running programs gets to output color data, for example. It
can
be used,
however, to select which of several units can begin code execution.
When a ColorPAL comes out of reset, any commands sent without prepending an address are assumed to
be broadcast and won’t be blocked. That way, it’s easy simply to ignore the networking feature if you
don’t want to use it.
Here’s some example code that speaks to two ColorPALs, one with address 01; the other, 02. Unit 01
will display the colors green, blue, and red in that sequence; unit 02, blue, green, and red. Both display
red because they are addressed using the broadcast address 00. Note that there are
no spaces
in the
sub-sequence, !+02=. This is because those three commands are all sent in Direct mode, which does
not permit spaces.