Here's a section of a routine I've use to decode RC5. It's pretty simple.
'// Philips RC5 IR decoder
DEFINE OSC 20
DEFINE LOADER_USED 1
DEFINE HSER_BAUD 2400
Y VAR WORD ' Holds 12-bit RC5 code
Loop VAR BYTE ' Loop variable
PIN VAR PORTB.0 ' RB.0 input pin reading data
TRISB.0=1 ' Set RB.0 direction to input
OPTION_REG.7 = 0 ' Internal pull-ups = on
Home:
IF PIN = 1 THEN Home ' Wait for low going pulse
PAUSEUS 100 ' Short delay
IF PIN = 1 THEN Home ' Was it noise?
PAUSEUS 1350 ' Pause to read 2nd half of 1st bit period
Y.0[13] = PIN ' Record 1st synch period bit value
FOR Loop = 12 to 0 STEP - 1 ' 13 pulses MSB to LSB
Y.0[Loop] = PIN ' Y.Bit.Loop = data bit
PAUSEUS 1800 ' Wait 1.8mS to read next RC5 bit
NEXT Loop ' in middle of 2nd bit period
IF Y.LowByte = $FF THEN Home ' Was it noise?
Y = ~Y & $003F ' Mask upper 10-bits to return 6-bit data
' in lower 6-bits of word result
HSEROUT ["Key Pressed = ",DEC Y,13,10]
Y=0 ' Clear key codes
PAUSE 250 ' Used for testing only
GOTO Home ' Return Home
Here's a tutorial on the RC5 protocol that will give you a better understanding of how & why the above code works.
http://www.xs4all.nl/~sbp/knowledge/ir/rc5.htm
Bookmarks