Extended NEC Protocol Decoder Using PIC12F1822 – CCS C

NEC IR remote control decoder with PIC12F1822

This topic shows how to decode IR remote control uses extended NEC communication protocol.
The complete extended NEC protocol message is started by 9ms burst followed by 4.5ms space which is then followed by the Address and Command. The address is 16-bit length and the command is transmitted twice (8 bits + 8 bits) where in the second time all bits are inverted and can be used for verification of the received message. The following drawing shows an extended NEC message example.

Extended NEC protocol message code

The NEC protocol uses pulse distance encoding of the bits. Each pulse is a 562.5µs long with carrier frequency of 38KHz. Logic bits are transmitted as follows:
Logic 0: 562.5µs pulse burst followed by a 562.5µs space, with a total transmit time of 1125µs (562.5 x 2).
Logic 1: a 562.5µs pulse burst followed by a 1687.5µs (562.5 x 3) space, with a total transmit time of 2250µs (562.5 x 4).

NEC protocol modulation

Extended NEC Protocol Decoder Using PIC12F1822:
Components List:

  • PIC12F1822 microcontroller
  • 1602 LCD
  • 10K Variable Resistor
  • 74HC595 Shift Register (74HC164, CD4094…..)
  • IR Receiver
  • 47µF Capacitor
  • 10K Resistor
  • +5V Power Supply
  • Protoboard
  • Jumper Wires

Extended NEC protocol decoder using PIC12F1822 circuit schematic is shown below where a 1602 LCD is used to display the NEC protocol parameters (address and command). To see how to interface this LCD with PIC12F1822 read the following topic:
Interfacing PIC12F1822 microcontroller with LCD display

PIC12F1822 Extended NEC protocol decoder circuit

In this project PIC12F1822 microcontroller internal oscillator is used and MCLR pin is configured to work as a digital input.
By adding the shift register we can make a low coast 3-wire LCD.
A pull-up resistor (10KOhm) between VCC and the IR receiver output pin minimizes the noise on that pin.
To see how to use 74HC164 or CD4094 instead of 74HC595 read the topic at the link above.

Extended NEC Protocol Decoder C code:
PIC12F1822 microcontroller internal oscillator is set to 8MHz with PLL enabled which makes the microcontroller runs at 8 x 4 = 32MHz. The following line is used to deo that:
setup_oscillator(OSC_8MHZ | OSC_PLL_ON);
Timer1 is set to increment by 1 every 1us:
SETUP_TIMER_1(T1_INTERNAL | T1_DIV_BY_8);
Timer1 is used to measure pulses and spaces duration in us.
The extended NEC message code has a total of 32 bits which can be divided into 3 parts:
The first 16 bits are for address (address low and address high)
The next 8 bits for command and the last 8 bits for the inverted command.
Basically the microcontroller waits until the IR receiver receives an IR signal which makes its output change its state from high to low. This is done using the following line:
while(input(IR_Sensor));
Where IR_Sensor is the pin where the IR receiver output connected to.
After that a function named nec_remote_read() is called, this function checks if the received signal has NEC protocol form all the time and reads the message code bits.
if(nec_remote_read())
Timer1 is used to calculate pulses and space in microseconds. For example to check the 9ms burst the following lines are used:
SET_TIMER1(0);
while(!input(IR_Sensor) && (count < 9500))
count = GET_TIMER1();
if( (count > 9499) || (count < 8500))
return FALSE;

The variable count is used to store Timer1 value. An interval between 8500us and 9500us is used to check the 9ms burst (9000us).
The same thing is done for the 4.5ms space.
The complete CCS C code for the NEC decoder is as the one below, it was tested with version 5.051.

NEC Protocol decoder with PIC12F1822 video:

Reference:
http://www.sbprojects.com/


Discover more from Simple Circuit

Subscribe to get the latest posts sent to your email.

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