Datasheet

Jon Waddington
102
Genrc5
''IR-Receiver (RC5)
VAR
long rc5 'rc5 code received
'byte flag
PUB init (pin)
{{Launch cog to detect RC5 codes}}
rxmask := |< pin 'mask input pin
full := (clkfreq/562) 'calculate bit times
thalf := full >> 1
quart := thalf >> 1
tquart := (thalf + quart)
cognew(@go, @rc5) 'begin RC5 cog
PUB getcommand : c
{returns command bits}
c := rc5 & $3F 'bit masking puts lowest 6 bits of rc5 into c
PUB getaddress : a
{returns address bits}
a := (rc5 & $7C0) >> 6 'rc5 is shifted right until bits 10 down to 6 are the LSBs, bit masking puts these bits into
a
PUB gettoggle : t
{returns toggle bit}
t := rc5 >> 11 'rc5 is shifted right until toggle bit is LSB
PUB retrc5 : rx
{returns full rc5 code}
rx := rc5 'returns current code in rc5
PUB getrc5 : rx
{waits for new rc5 code}
repeat until retrc5 <> rc5
rx := rc5
PUB flush
rc5 := rc5 & $8000
'flag := 0
DAT
org 0
go mov addr, PAR
mov outmask, dira 'backup dira in outmask
xor outmask, rxmask 'xor rx pin with outmask
and dira, outmask 'and' 'xor'ed outmask with dira
detect mov rxcode, #0
mov count, cnt
add count, delay
waitcnt count, 0
waitpne rxmask, rxmask 'Wait for start bit
mov start, cnt 'time start bit pulse
waitpeq rxmask, rxmask
mov half, cnt