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 the PIC compiler. Let’s make our ‘SONY SIRC Remote Controlled device using PIC Micro-controller and mikroC’.

Disclaimer: Electricity is always dangerous. Proper skill is required to work with electricity. Do work at your own risk. The author will not be responsible for any misuse or harmful act or any mistake you make. The contents of this website are unique and copyright protected. Kindly don’t do any nonsensical act copying and claiming it as yours. Most of the articles published here are kept as open-source to help you. Take the knowledge for free and use it, but if you are interested you can buy the ready resources offered here. If you need any help or guide feel free to comment below, the author will try to help 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 remote-controlled systems. 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:

SONY SIRC Remote Controlled
Circuit diagram of our remote controller

MikroC Code with the library:

Here is the library of the SONY SIRC remote decoder. I used mikroC pro for PIC with a valid license. If you are having a 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.

https://www.youtube.com/watch?v=D3y_GrdjzjA

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.

Loading

JLCPCB – Only $2 for PCB Prototype (Any Color)

24 Hours fast turnaround, Excellent quality & Unbeatable prices

$18 Welcome Bonus for new registrations Now!!! https://jlcpcb.com


Check this out: 5 coolest multimeters you can buy


MKDas

I'm Mithun from Bangladesh. Electronics is my passion, love to work with electronics. This is my personal blog. Besides my regular works, I write some articles here. Most of them are open-source and everything is presented in the easiest way so that anyone can understand and learn it. Thanks.

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

Avatar placeholder

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