NEC IR Remote Control Interface with 8051
IR Remote Controllers and receivers follow standard protocols for sending and receiving the data. Some of the standard protocols are NEC , JVC , SIRC (Sony Infrared Remote Control) etc. We will be discussing only the NEC protocol. After understanding the frame format of IR Remote, We will be interfacing a IR receiver with 8051 and decode the key pressed.
NEC IR protocol encodes the keys using a 32bit frame format as shown below.
|NEC Frame Format|
|Address||Complement of Address||Command||Complement of Command|
Each bit is transmitted using the pulse distance as shown in the image.
Logical '0': A 562.5µs pulse burst followed by a 562.5µs space, with a total transmit time of 1.125ms
Logical '0': A 562.5µs pulse burst followed by a 1.6875ms space, with a total transmit time of 2.25ms
When a key is pressed on the remote controller, the message transmitted consists of the following, in order:
- A 9ms leading pulse burst (16 times the pulse burst length used for a logical data bit)
- A 4.5ms space
- The 8-bit address for the receiving device
- The 8-bit logical inverse of the address
- The 8-bit command
- The 8-bit logical inverse of the command
- A final 562.5µs pulse burst to signify the end of message transmission.
The four bytes of data bits are each sent least significant bit first. Below image illustrates the format of an NEC IR transmission frame, for an address of 00h (00000000b) and a command of ADh (10101101b).
IR Key Codes
Below table gives the complete list of Codes for NEC IR Remote.
Below is the sample code to decode the key pressed on IR remote control and send on UART. We need an External interrupt to detect the pulses and timer to measure these pulse widths.
- INT0(P2.2) will be configured as falling Edge interrupt to detect the pulses.
- Timer0(Mode1) will be configured to generate a periodic interrupt of 1ms.
First two transitions will be ignored as they will mark SOF(Start of the frame). After this continuously 32-bit information will be captured in a variable. If the pulse width is greater than 2ms then it will be considered as LOGIC-1 else as LOGIC-0. If the pulse width is greater than 50ms then it will be considered as SOF(Start of the frame).
1ms Delay Calculation:
- Clock Freq=11.0592 Mhz
- Machine Cycle = 12
$$TimerValue= 65536 - ((Delay * ClockFreq)/Machine Cycle)=65536-((1ms * 11.0592Mhz)/12) = 65536 - 921= 0xFC67$$
Using IR Remote Library
Download the complete project folder from this link: Examples and Code Library
Have an opinion, suggestion , question or feedback about the article let it out here!