Philips TV remote decoder using PIC16F84A


RC-5 protocol:
The protocol uses bi-phase modulation (or so-called Manchester coding) of a 36KHz IR carrier frequency. All bits are of equal length of 1.778ms in this protocol, with half of the bit time filled with a burst of the 36KHz carrier and the other half being idle. A logical zero is represented by a burst in the first half of the bit time. A logical one is represented by a burst in the second half of the bit time.
when a button in remote is pressed, in transmits a 14 bit IR signal modulated as above. Now, the 14 bit signal is represented as below.
>>  The first two pulses are the start pulses, and are both logical "1". Please note that half a bit time is elapsed before the receiver will notice the real start of the message. 
>>  The 3rd bit is a toggle bit. This bit is inverted every time a key is released and pressed again. This way the receiver can distinguish between a key that remains down, or is pressed repeatedly.
>> The next 5 bits represent the IR device address, which is sent with MSB first. The address is followed by a 6 bit command, again sent with MSB first.
>>   A message consists of a total of 14 bits, which adds up to a total duration of 25 ms. Sometimes a message may appear to be shorter because the first half of the start bit S1 remains idle. And if the last bit of the message is a logic "0" the last half bit of the message is idle too.
>> As long as a key remains down the message will be repeated every 114ms. The toggle bit will retain the same logical level during all of these repeated messages. It is up to the receiver software to interpret this auto repeat feature.

Predefined commands:

$00 - 0TV1
$01 - 1TV2
$02 - 2Teletext
$03 - 3Video
$04 - 4LV1
$05 - 5VCR1
$06 - 6VCR2
$07 - 7Experimental
$08 - 8Sat1
$09 - 9Camera
$0A - 10Sat2
$0B - 11
$0C - 12CDV
$0D - 13Camcorder
$0E - 14
$0F - 15
$10 - 16Pre-amp
$11 - 17Tuner
$12 - 18Recorder1
$13 - 19Pre-amp
$14 - 20CD Player
$15 - 21Phono
$16 - 22SatA
$17 - 23Recorder2
$18 - 24
$19 - 25
$1A - 26CDR
$1B - 27
$1C - 28
$1D - 29Lighting
$1E - 30Lighting
$1F - 31Phone

TV CommandVCR Command
$00 - 000
$01 - 111
$02 - 222
$03 - 333
$04 - 444
$05 - 555
$06 - 666
$07 - 777
$08 - 888
$09 - 999
$0A - 10-/---/--
$0C - 12StandbyStandby
$0D - 13Mute
$10 - 16Volume +
$11 - 17Volume -
$12 - 18Brightness +
$13 - 19Brightness -
$20 - 32Program +Program +
$21 - 33Program -Program -
$32 - 50
Fast Rewind
$34 - 52
Fast Forward
$35 - 53
$36 - 54
$37 - 55



       IR receiver used here is a TSOP1738. It is an active low device. Its o/p will become low while it is exposed to 38kHz modulated IRsignal. It filter out the 38kHz carrier and provides the message signal at the o/p. This o/p is connected to an external intrerrupt pin of PIC16F84A. When a key in remote is pressed, the start bit will make the TSOP o/p low for first 889us. At this first high to low transition at RB0, an external interrupt will occur. Then the PIC will handle the ISR instantly. Then in ISR, we could sample the RB0 pin at some regular interval of time(as in below program) and thus we could obtain the command bits. Then according to the command, we could  activate or deactivate different port bits.


#include <pic.h>
#define _XTAL_FREQ 4e6
#define us __delay_us
#define ms __delay_ms
unsigned char buf,flag;
void interrupt external() //ISR
                for(int a=0;a<6;a++)
                buf&=0b00111111; //filtering the 6 command bits
                RA3=1;ms(30);RA3=0; //indicator LED


TRISB=1;        //set RB0 as i/p and all other portb bits as o/p
TRISA=0;        //set PORTA as o/p
GIE=1;            //global interrupt enable
INTE=1;         //external interrupt enable
INTEDG=0;   //interrupt edge selection
    else if(buf==3){RB2=~RB2;ms(200);}
    else if(buf==13){RB3=~RB3;ms(200);}
    else if(buf==12){RB4=~RB4;ms(200);}
    else if(buf==32){RB5=~RB5;ms(200);}
    else if(buf==33){RB6=~RB6;ms(200);}
    else if(buf==4){RB7=~RB7;ms(200);}
    else if(buf==7){RA0=~RA0;ms(200);}
    else if(buf==6){RA1=~RA1;ms(200);}
    else if(buf==9){RA2=~RA2;ms(200);}


  1. Hello Vinu

    I tried your coding with mikro C it shows errors for coding ! & some other same results please let us know what is suitable compiler for this coding if can post hex file which would make our life easier

  2. :020000000F28C7

  3. hi,
    which compiler you are using for this code??

    thanks for all tutorial and code, it helps a lot....
    Good Luck

  4. hi vinod,
    I tried your coding with PIC16F877a.decoding output not getting properly.i dont know how to fix this....pls help me.. i got some same buffer values ....

  5. This comment has been removed by the author.

  6. hi vinod,I tried your coding with PIC16F877a with
    HI-TECH C Compiler for PIC10/12/16 MCUs (PRO Mode) V9.70
    cgpic.exe has stopped working

  7. hello sir i have a vire remote please see below link
    can i use this remote to decode ? please reply ?

  8. Hello Vino

    I tried your coding with flow code v5 it shows errors for coding ! & please let us know what is
    coding suitable for this compiler if you can