IR Remote control transmitter and receiver with CCS C compiler

5-Channel IR remote control system using PIC microcontroller

This topic shows how to make a simple infrared (IR) remote control system using the microcontroller PIC12F1822. This IR system has two circuits as known: IR transmitter circuit and IR receiver circuit. Both circuit based on the same microcontroller type which is PIC12F1822.
This IR system uses NEC communication protocol. To see how the NEC protocol works read the following topic which shows how to decode this communication protocol using PIC12F1822 microcontroller.
Extended NEC Protocol Decoder Using PIC12F1822 – CCS C

Components List:
Transmitter Circuit:

  • PIC12F1822 Microcontroller
  • IR Transmitter
  • 2N2222 Transistor
  • 5 Push Buttons
  • 10k Resistor
  • 100Ohm Resistor
  • +5V Power Source
  • Protoboard
  • Jumper Wires

Receiver Circuit:

  • PIC12F1822 Microcontroller
  • IR Receiver
  • 5 LEDs
  • 10k Resistor
  • 5 x 470 Ohm Resistors
  • 47uF Capacitor
  • +5V Power Source
  • Protoboard
  • Jumper Wires

NEC Protocol IR transmitter (Encoder) using PIC12F1822:
The following image shows the IR system transmitter circuit schematic diagram.

IR remote control transmitter circuit

In the circuit there 5 push buttons and each button sends a different IR signal code. The IR transmitter is the element that sends the IR signals to the IR receiver circuit.
The NPN transistor 2N2222 is used to drive the IR transmitter because the IR transmitter consumes high current and the microcontroller generally can’t provide that amount of current.
PIC12F1822 internal pull-ups are enabled by the software and the internal oscillator is used as usual.

NEC Protocol IR transmitter (Encoder) using PIC12F1822 CCS PIC C code:
This is the full code of microcontroller of the NEC IR transmitter.
The NEC protocol carrier frequency is 38KHz and to generate this frequency PIC12F1822 CCP module is used as a PWM module. The flLowing CCS C line is used to configure the PWM module:
#use pwm (PWM1, FREQUENCY = 38KHz, DUTY = 25, PWM_OFF)
The internal oscillator is used and set to 8MHz with PLL enabled (8 x 4 = 32MHz). The following line is used for that:
setup_oscillator(OSC_8MHZ | OSC_PLL_ON);
In the circuit there are 5 push buttons connected to RA0, RA1, RA3, RA4 and RA5 which means that pins must be configured as inputs and the PWM pin as output.
Internal pull-ups are enabled for the input pins with the following line:
The five buttons transmit the following signals respectively:
0x40BF00FF — 0x40BF807F — 0x40BF40BF — 0x40BF20DF — 0x40BFA05F
1s and 0s are transmitted as:
Transmit 1 : pwm_on();
Transmit 0: pwm_off();
For example the transmission of 9ms burst pulse and 4.5ms space:
// Send 9ms burst
  // Send 4.5ms space
Full Code:

NEC Protocol IR receiver (Decoder) using PIC12F1822:
The NEC receiver circuit schematic is shown below.

IR remote control receiver circuit

In the IR receiver circuit there are 5 LEDs and IR receiver. The IR receiver receives IR signals transmitted from the IR transmitter. Each LED is remotely controlled from one button in the transmitter circuit.
PIC12F1822 internal oscillator is used and MCLR pin is configured as a digital input pin.

NEC Protocol IR receiver (Decoder) using PIC12F1822 CCS PIC C code:
As in the IR transmitter the internal oscillator of the IR receiver microcontroller is used.
Timer1 is configured to increment every 1us and it is used to measure pulses spaces duration.
For example to check the 9ms pulse the following lines are used:
// Check 9ms pulse (remote control sends logic high)
while(!input(IR_Sensor) && (count < 9500))
count = GET_TIMER1();
if( (count > 9499) || (count < 8500))
return FALSE;
And checking the 4.5ms space as follows:
// Check 4.5ms space (remote control sends logic low)
count = 0;
while((input(IR_Sensor)) && (count < 5000))
count = GET_TIMER1();
if( (count > 4999) || (count < 4000))
return FALSE;
Full Code:

IR Remote control transmitter and receiver using PIC12F1822 microcontroller video:
The following video shows project final result.

2 thoughts on “IR Remote control transmitter and receiver with CCS C compiler”

  1. please help me, how do I port the code of the transmitter and receiver to pic 10F322 ? This pic has no 16-bit timer1, only 8-bit timer0 and timer2. would it be possible for you to help me?

  2. I’m using CCS C v5.103 and I’m having problems getting the receiver to respond to remote commands, the code compiled just fine, but I’m not sure if it’s being compiled correctly, thanks for any responses.

Leave a Comment

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Scroll to Top