SONY SIRC Remote Controlled device using PIC Micro-controller and mikroC

Published by MKDas on

In this article, we are going to make our own remote-controlled device using SONY SIRC remote protocol. In the previous article, we have learned the basic pattern of this protocol and now we will use that in our circuit. We’ll use PIC12F675 micro-controller and mikroC Pro for PIC compiler. Let’s start!

Disclaimer: Electricity is always dangerous. Skill required to work with electricity. Do work with your own risk. Author will not be responsible for any misuse or harmful act. This website contents is also copyright protected. Anything copied and directly posted in your website and claiming it as yours is prohibited and nonsensical. Author published all the articles as opensource to help you making your project and learning purpose only. Learn and make one for yourself. If need any help feel free to ask the author. Author will be helpful to you. Thanks.

About SONY SIRC:

In my previous article, I’ve explained this protocol. Please read that article first to learn about SONY SIRC. SIRC protocol is one of the most common protocols in the remote-controlled system. This protocol uses a start bit, then a command and then an address bit. All these are transmitted at 40KHz modulation. A remote sensor is used to receive that modulated signal and decode the pattern. After that, micro-controllers are used further to decode the command and address from that received signal.

Circuit Diagram:

Circuit diagram of our remote controller

MikroC Code with the library:

Here is the library of SONY SIRC remote decoder. I used mikroC pro for PIC with valid license. If you are having problem building the hex let me know.

sbit ir_rx at GP3_bit; // Sensor pin

// function prototypes
void get_mark_time(void);


// global variables
unsigned char counter = 0;
unsigned char bitcount;
unsigned char ir_address;
unsigned char ir_command;
unsigned int mark_time;

void interrupt() iv 0x0004 ics ICS_AUTO
{
    if (TMR0IF_bit)
    {
        counter++;              // increment counter
        TMR0IF_bit = 0;         // Clear Timer0 overflow interrupt flag
    }
}

void main() 
{
  CMCON = 0x07;                 // disable comparator
  ANSEL = 0x00;                 // disable analogue
  OPTION_REG = 0x03;            // TMR0 prescaler set to 1:16
  TRISIO = 0x08;                // IR GP3 = input, rest output
  GPIO = 0x00;                  // all outputs off
  
  // start timer 0 counting
  GIE_bit = 1;                  // Global interrupt enable
  T0IE_bit = 1;                 // Enable Timer0 overflow interrupt
  
  while(1)
  {
      
      
      ir_command = 0;
      ir_address = 0;
      get_mark_time();
      if ((mark_time > 120) && (mark_time < 200))  // set the frequency limit
      {
          for(bitcount = 0 ; bitcount < 7 ; bitcount++)
          {
              get_mark_time();                               // get a Sony IR bit
              ir_command >>= 1;                              // shift
              ir_command &= 0x7f;                            // top bit zero
              if (mark_time > 0x40)
              {
                  ir_command ^= 0x80;                        // top bit 1
              }
          }
          ir_command >>= 1;                                  // shift 1 unused bit
          ir_command &= 0x7F;                                // clear top bit

          for(bitcount = 0 ; bitcount < 5 ; bitcount++)
          {
              get_mark_time();                               // get a Sony IR bit
              ir_address >>= 1;                              // shift
              ir_address &= 0x7f;                            // top bit zero
              if (mark_time > 0x40)
              {
                  ir_address ^= 0x80;                        // top bit 1
              }
          }
          ir_address >>= 3;                                  // shift 3 unused bits
          ir_address &= 0x1F;                                // clear top 3 bits
      }
      
      
      
      
      
      
      if(ir_address == 1)
      {                                                      // TV
          if(ir_command == 0)
          {                                                  // button 1
              GP0_bit = ~GP0_bit;
          }
          if(ir_command == 1)
          {                                                  // button 2
              GP1_bit = ~GP1_bit;
          }
          if(ir_command == 2)
          {                                                  // button 3
              GP2_bit = ~GP2_bit;
          }
          
          Delay_ms(200);                                     // avoid double toggle
      }
      
      
      
      
      
      
  }
}

// get time of mark, then ignore space
void get_mark_time(void)
{
    while(ir_rx);                           // wait for a mark
    counter=0;
    TMR0 = 0;
    while(!ir_rx);                          // wait for space
    mark_time = (counter << 8) + TMR0;      // collect integer mark time
}

Download the hex file instead.

Test result:

I’ve made a video for this purpose. Please play this video.

Conclusion:

I hope this project was helpful to you. If you make one for yourself, it will be a great pleasure for me. Anywhere you need help, let me know. Please share this project and subscribe to my blog. Thank you.


MKDas

Mithun K. Das; B.Sc. in EEE from KUET. Blog: https://labprojectsbd.com

3 Comments

Ajape · March 18, 2021 at 9:44 am

thank you for the new development, more grace to you

Joy · March 29, 2021 at 1:26 am

Sir i want change remote but what can i do ?.

Leave a Reply

Your email address will not be published. Required fields are marked *