The RC5 decoder based on a PIC16F877A and PIC-01 Developement Board.

27 January, 2007 (10:54) | Microchip PIC, Projects | By: glogin

1. Introduction.
It is an example of an RC5 receiver and decoder. It shows popular Philips RC5 coding. It was tested using simple hardware assembled on the PIC-01 Development Board connected to a PC through an RS232. All of the routines were written in C using the CCS compiler.

2. A little bit of theory.

The RC5 is Philips’ standard for infra red communication. It is widely used for remote controls in consumer electronics.

The RC5 uses Manchester coding. It is a form of data communications line code in which each bit of data is signified by at least one transition. Manchester coding is considered to be self-clocking, which means that accurate synchronization of data stream is possible. Each bit is transmitted over a predefined time period. Manchester codes have a transition at the middle of each period.

The RC5 code uses a modulation of a 36kHz IR carrier frequency. The code is 14-bit long. A 5-bit address and a 6-bit command are preceded by 3 control bits.

Drawing 1. (large view)
rc5 circuit

The first two start bits are both logical ’1′. The third bit is a toggle bit. This bit is inverted every time a key is released and pressed again. The next 5 bits represent the IR device address, and the following 6 bits represent the command. Addresses and commands are sent in the MSB first order.

3. Hardware.

The TSOP1736 is a miniature receiver for infra red control systems. It works in its typical application circuit. The U1 output pin is connected to the RB0 pin of the PIC microcontroller. The output pin of the U1 is normally high. Receiving an infra red signal pulls the output low and the microcontroller can decode the information in an interrupt call.

Because the PIC uses an interruption on RB0 input, the LED jumper on the PIC-01 Development Board should be removed.

Drawing 2. (large view)
rc5 circuit

4. Listing.

The output of the TSOP1736 is normally high and the RC5 code on its output is inverted. A low signal on the PIC input calls an interrupt routine. The microcontroller waits for a high level and times how long the low state has remained. If the time has been 800-1000us, the PIC starts decoding. It reads the input approximately every 1.78ms and writes data into a buffer. After that the address and command are displayed on an LCD and sent through the RS232.

The code was written in C and tested on the PIC development board by LoginWay.

//—————————————————–
//rc5.c
//—————————————————–

#include<16f877a.h>
#use delay (clock=4000000)
#fuses xt,nowdt,noprotect,noput,nolvp
#use rs232 (Baud=9600,xmit=pin_c6,rcv=pin_c7) //RS232 transmission setup
#include”lcd_new.h”

int counter,i,com,adr;
int16 buffer;

#int_ext //interrupt
int_IR()
{
counter=0; //reset counter and buffer
buffer=0;
disable_interrupts(int_ext); //disable interrupts

while(!input(pin_b0)) //wait for high level
{ delay_us(15);
++counter; } //time how long has been low
if(counter>=38&&counter<=45) //if from about 800 to 1000 us
{ //do routines
delay_us(200);
for(i=0;i<13;i++) //13 following bits
{
if(input(pin_b0)) //if the input high
{bit_set(buffer,0); //set the LSB and shift left
buffer<<=1;}
else //otherwise just shift
buffer<<=1;
delay_us(1740); //wait for naxt bit
}
buffer>>=1; //shift 1 right because of last reading
com=buffer&0b00111111; //command is 6-bit long; ignore the rest
buffer>>=6; //shift 6 right
adr=buffer&0b00011111; //address is 5-bit long; ignore the rest

//display on an LCD
printf(lcd_putc,”\fAddress:%u\nCommand:%u”,adr,com);
printf(“A%uC%u”,adr,com); //send bytes to the rs232
delay_ms(150);} //wait
return(0); //return to main
}

main()
{

lcd_init();
while(1)
{
enable_interrupts(int_ext); //enable external interrupt
ext_int_edge(H_to_L); //falling edge
enable_interrupts(global); //enable interrupts
}
}

5. Usage.

You can connect your PIC-01 Development Board to the PC through an RS232 serial straight-through cable. To check your program use the Hyper Terminal. Set the appropriate COM port and set the transmission on 9600bd, no parity, 1-bit stop, no flow control.

You can use your RC5 remote controller to control some of your computer applications like WinAmp and Windows Media Player.

To find out more follow the links below.

The TSOP1736 data sheet.
RC5.hex (.rar) file is available here.
Here you can find WinAmp plug-in and some instructions how to install it.
Some useful information about the IR remote control.

Bad Behavior has blocked 58 access attempts in the last 7 days.