PDA

View Full Version : Decode RC5 ?



charudatt
- 20th March 2004, 06:16
Hello Guru's

Any code available for decoding RC5 (IR) signals using PICBASIC Pro.

Thank you.

Bruce
- 4th April 2004, 06:04
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

charudatt
- 5th April 2004, 05:41
Hello Bruce,

Thanks a lot with the help on the RC5 Code. I must say that you'll at Rentron are really doing a good job in educating people with programing. I am sorry to use this foroum to say a few words, but nevertheless I steal the opportunity.

regards
Charudatt

Bruce
- 7th April 2004, 03:00
You're welcome. I just posted a short tutorial on creating your own infrared encoder & decoder ICs with PBP if you're interested.

http://www.rentron.com/PicBasic/IR_Chips.htm

The same code allows the PIC to function as encoder or decoder by selecting the mode on power-up. It compiles to only 495 words so it will fit into the 16F627 or 628.

charudatt
- 7th April 2004, 06:12
Hello Bruce,

Thank you for being so kind with the explanation and I am sure a lot of people would benifit on this group.

What modification would I need to do to adapt it to RF work ?

regards

Charudatt

Bruce
- 7th April 2004, 06:26
Hi Charudatt,

You would have better results using a protocol similar to the RC5 example for RF since it's manchester type encoding. You don't want or need the 40kHz modulation routine like the one in the IR Chips project for RF.

The purpose of modulating IR data at 40kHz is because this is the pass-band frequency of the IR detector module used for the project.

Visit the RC5 tutorial link in my previous post. It's very simple to implement something similar for an RF link.

jrt4fun
- 21st April 2004, 11:12
Bruce,

First of all thanks for the code.

I tried out your program and I get some data in.
However depending on the angle I keep getting other values when pressing the same button (distance about 60cm)
I know there is a toggle bit that changes when pressing the same button twice but this should not affect the 'data' part of the RC5 that is filtered out here.
I have to say that I run the program with a 10MHz crystal instead of 20MHz as specified in your program.
Can this be the cause?

Thank you.

Best regards

charudatt
- 3rd November 2005, 11:12
Hello Bruce,

Tried your program on a 16F72 MCU and it works. I get some consistant data on Keypress but it does not tally with the key I pressed. I have a very similar code in PICBASIC PLUS (PROTON) and it works OK.

Just wanted to ask you:

1. How do I remove the address code from the data
2. A couple of keys don't get registered , any idea. Namely #7

Once again thank you for your help.

regards
Charudatt