Philips TV remote decoder using PIC16F84A

INTRODUCTION:


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:

RC-5
Address
Device
$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


RC-5
Command
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
Play
$36 - 54
Stop
$37 - 55
Recording


    

CIRCUIT DIAGRAM



DECODING:
       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.



PROGRAM:

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

}

main()
{
__delay_ms(100);
PORTB=0;
PORTA=0;
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
while(1)
    {
    flag=0;
    if(buf==1){RB1=~RB1;ms(200);}
    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);}
    flag=0;
    while(flag==0);
    }
}

13 comments :

  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

    ReplyDelete
  2. :020000000F28C7
    :10000800CE00030E83128E0004088F000A089000A9
    :100018004F0891002129B529823083129500DD30DF
    :100028009400940B1528950B15281A28831286011D
    :10003800850101308316860085018B170B16011385
    :100048002528831298011708013A031D2C282D280A
    :100058003D28023086060230960004309500BA30FA
    :100068009400940B3528950B3528960B3528640099
    :10007800152983121708033A031D432844285428D6
    :10008800043086060230960004309500BA30940099
    :10009800940B4C28950B4C28960B4C28640015297A
    :1000A800831217080D3A031D5A285B286B2808305D
    :1000B80086060230960004309500BA309400940BFE
    :1000C8006328950B6328960B63286400152983120F
    :1000D80017080C3A031D71287228822810308606EA
    :1000E8000230960004309500BA309400940B7A28B8
    :1000F800950B7A28960B7A2864001529831217081D
    :10010800203A031D8828892899282030860602303D
    :10011800960004309500BA309400940B9128950B02
    :100128009128960B91286400152983121708213A03
    :10013800031D9F28A028B02840308606023096006C
    :1001480004309500BA309400940BA828950BA82881
    :10015800960BA8286400152983121708043A031D72
    :10016800B628B728C72880308606023096000430A3
    :100178009500BA309400940BBF28950BBF28960BB6
    :10018800BF286400152983121708073A031DCD28D4
    :10019800CE28DE280130850602309600043095000E
    :1001A800BA309400940BD628950BD628960BD628EF
    :1001B8006400152983121708063A031DE428E52868
    :1001C800F528023085060230960004309500BA30D2
    :1001D8009400940BED28950BED28960BED28640000
    :1001E800152983121708093A031DFB28FC2815292D
    :1001F800043085060230960004309500BA30940029
    :10020800940B0429950B0429960B042964001529DD
    :1002180015291529152915291529152915291529E6
    :10022800152983129801192919291808031D1D2950
    :1002380019292528252825280F288B10061825294F
    :100248002629AA2921308C008C0B2829831206180C
    :100258002E292F29AA2921308C008C0B31298312B1
    :10026800061837293829AA29DE308C0064008C0B3F
    :100278003A298312061C41294229AA29DE308C001A
    :1002880064008C0B4429831206184B294C29AA298F
    :100298000E308D00CD308C008C0B50298D0B5029E1
    :1002A800552983129701920193011308803ACF00D0
    :1002B80080304F02031D622906301202031C652993
    :1002C800662968299229922903108312970D061C22
    :1002D8006E296F29742901308C000C08970774293E
    :1002E800FD308C00772978298C0B76297B297C298D
    :1002F8007D290130831292070318930A003093076F
    :100308001308803ACF0080304F02031D8D29063034
    :100318001202031C90299129682992293F308312DF
    :100328008C000C08970598010314980D8515273043
    :100338008D00F5308C008C0B9F298D0B9F29831223
    :100348008511AA29AA29AA29AA29AA291108CF0008
    :1003580010088A000F0884000E0E8300CE0E4E0E81
    :0A0368000900970198018301102895
    :02400E00FA3F77
    :00000001FF

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

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

    ReplyDelete
  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 ....

    ReplyDelete
  5. This comment has been removed by the author.

    ReplyDelete
  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

    ReplyDelete
  7. hello sir i have a vire remote please see below link
    http://www.hothome.cn/manage/UploadImages/rmn/rmn002.jpg
    can i use this remote to decode ? please reply ?

    ReplyDelete
  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

    ReplyDelete
  9. dear please explain decoder o/p connections to lcd1602

    ReplyDelete
  10. Now this is really some good post i am reading after a long time. Love what you share and write for us. You really have an amazing blog. Great thanks. Independence Day Greetings

    ReplyDelete