Parallax, Inc. • IR Buddy Demo Kit (#28016) • 11/2002
Page 3
In a typical application, the command to receive RC-5 codes would be immediately followed with a
SERIN
function to accept the data.
Example:
SEROUT pin, baud, [$72, 10]
SERIN pin, baud, [STR buffer\8\255]
The first line above sends the RC-5 receive command and specifies a 10 millisecond holdoff period. The
second line will accept the data into an eight-byte array called buffer. The \8 parameter tells
SERIN
to
accept eight bytes of data. The trailing \255 parameter tells
SERIN
to terminate if the value 255 is
encountered in the input stream.
This syntax allows the BASIC Stamp to retrieve all the available key codes from the IR Buddy, regardless
of the actual number buffered (up to four codes; two bytes per code). The IR Buddy uses the value 255
to identify an unused position in the buffer. The end of the buffered data is signified with the value 254.
For example, if the IR Buddy buffered key codes for numbers "1" and "2" from a typical television
remote, the IR Buddy buffer would contain the following data:
0 1 0 2 254 255 255 255
The first two bytes are the system and command codes for "1," the second two bytes are the system and
command codes for "2." The fifth byte, 254, signifies the end of data in the buffer. The rest of the
buffer is padded with the value 255. Note that (with the syntax specified above)
SERIN
will terminate
upon reading the first 255.
The IR Buddy uses one additional special value: 253. This value tells the BASIC Stamp that the last key
code has been repeated without an intermediate release. The value 253 will appear in the buffer when a
remote key is pressed and held.
$74 Transmit RC-5 Key Code
Use:
SEROUT
pin
,
baud
, [$74,
repeats, modulation, system, command
]
pin
variable or constant value: 0 to 15
baud
variable or constant value for 2400, 4800 or 9600 baud; open-mode
repeats
variable or constant value: 0 to 255; number of repeats of this key code
modulation variable or constant value: 30, 38 or 56; IR modulation frequency in kilohertz
system
variable or constant value: 0 to 31; system code
command
variable or constant value: 0 to 63; command value
This command directs the IR Buddy to transmit any one of the 2048 unique key codes using the Philips
RC-5 protocol. Each key code consists of a five-bit system code and a six-bit command. This function
will always send the key code once at the specified modulation frequency (30, 38 or 56 kHz), followed by
the specified number of repeats.
Once the IR Buddy begins transmitting the key code, it will pull the serial line low to indicate its busy
state. This line can be monitored by the BASIC Stamp to prevent resetting the IR Buddy or otherwise
disrupting a transmission in progress.