Infrared IR Receiver

Program Download:

Main C File
Infrared_IR_Receiver.c

The Software
There are two main portions of code that we are concerned with:
-Decoding The Input IR Signal
-Acting On The Input Command


The decoding process takes place very frequently and so the CCP modules are used to detect both rising and falling edges so that the time for each pulse can be accurately determined. Since there is no PIC functionality for triggering interrupt on every rising and falling edge, we have to swap that option inside the interrupt routine. Here is a short excerpt of how the IR signal is decoded.

Decoding The Input IR Signal

------------« Begin Code »------------
..
...
..
          //Pause Between Command/Data Pulse
          if( all_time[q] < 0x8000 && all_time[q] > 0x1800 ){
               current_command = ir_data;
          // Don't Care About Pause
               ir_data = 0x0;
          }
          // Digital Data: 00
          else if( all_time[q] < 0x460 && all_time[q] > 0x440){
               ir_data = ir_data << 2;
               //ir_data += 0b00; //Redundant And Not Necessary
          }
          //Digital Data: 0
          else if( all_time[q] < 0x208 && all_time[q] > 0x1E0){
               ir_data = ir_data << 1;
               ir_data += 0b0;
          }
..
...
..
          //Header Packet
          if( all_time[q] < 0xB70 && all_time[q] > 0xB90){
          // Don't Care About Header
               ir_data = 0x0;
          }
          // Digital Data: 11
          else if( all_time[q] < 0x490 && all_time[q] > 0x470){
               ir_data = ir_data << 2;
               ir_data += 0b11;
          }
          //Digital Data: 1
          else if( all_time[q] < 0x238 && all_time[q] > 0x218){
               ir_data = ir_data << 1;
               ir_data += 0b1;
          }
..
...
..
------------« End Code »------------

Using the pause lengths for each pulse already determined in the second theory section, each if statement will add to the ir_data integer the appropriate value. Notice that bits are being shift in. This will save more space instead of using raw decimal numbers.

One thing that isn't shown above but it important to note. The two chunks of codes are contained within another if statement that gets triggered depending upon if the last edge detected was a rising edge or a falling edge. This is important because some of the commands seen above can only be triggered if a rising edge last detected or vise-versa. Either-way take a look at the code to get a better feel for that.

Acting On The Input Command

I won't bother putting another chunk of code here that shows how the commands are handled, but in all honesty it is just a simple switch statement:
switch(active_command){
case ... :
..
...
default :
}
The switch statement runs the specific code for each button and afterward clears out the command buffers so that the command is not run or evaluated twice without the user pressing the button twice.

One last thing I'll mention about the way the firmware works is that there is a small error checking routine within the CCP interrupt that checks to see if the last received command is the same as the current received command. This means in order for a command to be passed through to the main-function, the user must hold down a button long enough for at least two commands to be sent from the remote to the IR receiver circuit.



;