Sony SIRC IR remote, hope you like it

General discussion on mikroC.
Post Reply
Author
Message
ch9fod
Posts: 54
Joined: 10 May 2008 22:08
Location: Mexico

Sony SIRC IR remote, hope you like it

#1 Post by ch9fod » 07 Feb 2009 19:41

So this code decodes the Sony SIRC IR remote controllers in the 12 bit interface. I know its not very clean and it can be very optimized, but it works and thats great for me hehe. I use the INT on RB0 and timer 1 for measuring the width of the pulses.
this picture is what i read on the exit of a TSOP1140 when i press the button 2 on the remote control.
Image

and this is the code:

Code: Select all

char edo,data,count,count2,add,wait;
unsigned time;

void interrupt(){
  if (INTCON.F1){
                 PORTD.F1^=1;
                 T1CON.TMR1ON=0;     //Stops the timer so i can measure the time
                 time=TMR1H;      //Stores timer1 in time variable
                 time=time<<8;
                 time=time|TMR1L;
                 TMR1H=0;            //Clears T1 High
                 TMR1L=0;            //Clear T1 Low
                 T1CON.TMR1ON=1;     //Re-enables the timer
                 edo++;              //Next state
                 wait=0;
                 INTCON.F1=0;        // clears INT0IF (external interrupt)
  }
}
void main (){
             //OSCCON|=0x60; //Oscilador Interno a 4Mhz
             ADCON1 = ADCON1 | 0x0F;
             TRISA=0;
             TRISD=0;
             TRISB=1;
             PORTA=0;
             PORTD=0;
             OPTION_REG.INTEDG = 1;    //RISING EDGE RB0
             INTCON = 0xD0;            //GIE,PEIE,INT0IE(EXTERNAL INTERRUPT RB0)
             //T1CON.T1OSCEN=1;
             edo=0;
             time=0;
             count=0;
             data=0;
             wait=1;
             while(1){
                      switch (edo){
                                   case 0: PORTD.F2=1;   //Idle time, waiting instruction
                                           PORTD.F4=0;
                                           wait=1;
                                           break;
                                                      
                                   case 1: PORTD.F2=0;
                                           PORTD.F3=1;   //START INSTRUCTION RECIVIED
                                           wait=1;
                                           break;

                                   case 2: PORTD.F3=0;
                                           if(time<1400)
                                           data.F0=0;
                                           else           //data<0>
                                           data.F0=1;
                                           time=0;
                                           wait=1;
                                           break;
                                           
                                   case 3: if(time<1400)
                                           data.F1=0;
                                           else            //data<1>
                                           data.F1=1;
                                           time=0;
                                           wait=1;
                                           break;

                                   case 4: if(time<1400)
                                           data.F2=0;
                                           else            //data<2>
                                           data.F2=1;
                                           time=0;
                                           wait=1;
                                           break;
                                           
                                   case 5: if(time<1400)
                                           data.F3=0;
                                           else            //data<3>
                                           data.F3=1;
                                           time=0;
                                           wait=1;
                                           break;
                                           
                                   case 6: if(time<1400)
                                           data.F4=0;
                                           else            //data<4>
                                           data.F4=1;
                                           time=0;
                                           wait=1;
                                           break;
                                           
                                   case 7: if(time<1400)
                                           data.F5=0;
                                           else            //data<5>
                                           data.F5=1;
                                           time=0;
                                           wait=1;
                                           break;
                                           
                                   case 8: if(time<1400)
                                           data.F6=0;
                                           else            //data<6>
                                           data.F6=1;
                                           time=0;
                                           wait=1;
                                           break;

                                   case 9: if(time<1400)
                                           add.F0=0;
                                           else            //add<0>
                                           add.F0=1;
                                           time=0;
                                           wait=1;
                                           break;
                                           
                                   case 10: if(time<1400)
                                           add.F1=0;
                                           else            //add<1>
                                           add.F1=1;
                                           time=0;
                                           wait=1;
                                           break;
                                           
                                   case 11: if(time<1400)
                                           add.F2=0;
                                           else            //add<2>
                                           add.F2=1;
                                           time=0;
                                           wait=1;
                                           break;

                                   case 12: if(time<1400)
                                           add.F3=0;
                                           else            //add<3>
                                           add.F3=1;
                                           time=0;
                                           wait=1;
                                           break;
                                           
                                   case 13: if(time<1400)
                                           add.F4=0;
                                           else            //add<4>
                                           add.F4=1;
                                           time=0;
                                           wait=1;
                                           break;
                                 }
                  if(edo==13){
                              PORTA=data;
                              data=0;
                              PORTD.F4=1;
                              edo=0;
                              T1CON.TMR1ON=0;
                              TMR1H=0;
                              TMR1L=0;
                              }
                  while(wait==1){
                  asm{
                      nop
                      }
                      }
                  }
}
If you have any questions, pm me :D
Ch9FOD

Post Reply

Return to “mikroC General”