RC5 Remote control decoder with PIC microcontroller | MPLAB Projects

This post shows how to decode IR (Infra-Red) remote controls which use Philips RC5 (RC-5) protocol using PIC16F887 microcontroller. Decoded results are displayed on 16×2 LCD screen.
The compiler used in this project is Microchip MPLAB XC8 (MPLAB X IDE with MPLAB XC8 compiler).

About RC5 protocol:
The RC-5 protocol was developed by Philips in the late 1980s as a semi-proprietary consumer IR (infrared) remote control communication protocol for consumer electronics.

The RC5 has 14 bits per 1 code transmission, the 14 bits can be divided into 4 parts:
The first 2 bits are start bits and they are always logic 1.
The third bit called toggle bit, it can be logic 1 or logic 0.
The next 5 bits are address bits, each device type has its address number for example TV address number is 0, CD player address = 20 …………
And the last 6 bits are command bits, each button has its command number.

For the same device for example TV all the remote control buttons have the same address but each button has its command.
The toggle bit changes whenever a button is pressed.
The RC5 protocol uses Manchester coding, logic 1 and logic 0 are coded as shown in the following drawing where toggle bit is 1, address = 0 and command is 2:

This Wikipedia page contains more details about the RC-5 protocol.

Related Projects:
To see how to interface PIC microcontroller with LCD module using MPLAB XC8 compiler, read the following post:
Interfacing LCD with PIC microcontroller | MPLAB Projects
NEC Remote control decoder with PIC microcontroller | MPLAB Projects

Hardware Required:

  • PIC16F887 microcontroller   —->  datasheet
  • IR Receiver
  • 16×2 LCD screen
  • 10k ohm variable resistor or potentiometer
  • 330 ohm resistor
  • 5V Power source
  • Protoboard
  • Jumper wires

RC5 Remote control decoder with PIC microcontroller circuit:
The following image shows project circuit diagram.

Remote control decoder using PIC16F887 MCU - MPLAB XC8 remote control

(All grounded terminals are connected together)

Generally the IR receiver has 3 pins: GND, VCC and data. The data pin is connected to pin RB0 of the PIC16F887 microcontroller.

The 16×2 LCD screen is connected to the PIC16F887 microcontroller as follows:
RS —> RD0 pin
E  —> RD1 pin
D4 —> RD2 pin
D5 —> RD3 pin
D6 —> RD4 pin
D7 —> RD5 pin
VSS, RW, D0, D1, D2, D3 and K are connected to circuit GND (ground)
VEE to the variable resistor (or potentiometer) output pin
VDD to +5V and A to +5V through 330 ohm resistor

VEE pin is used to control the contrast of the LCD. A (anode) and K (cathode) are the back light LED pins.

In this project the PIC16F887 microcontroller runs with its internal oscillator @ 8 MHz, MCLR pin is configured as an input pin.

The following drawing shows how the IR receiver receives (infra-red signals that comes from the remote control) and transmits data to the microcontroller:

NEC Remote control decoder with PIC microcontroller C code:
The C code below is for MPLAB XC8 compiler, it was tested with version 2.00 installed on MPLAB X IDE version 5.05.

To be able to compile the C code, a small LCD library for MPLAB XC8 compiler is required which can be downloaded from the following link:

after the download, add the library file (LCD_Lib.c) to project folder.

Programming hints:
Before writing the C code of the decoder, I drew a simple state machine of the RC5 protocol which helped me a lot in the code. The state machine is shown below.

RC-5 protocol state machine

SP : Short Pulse (About 889µs)
LP : Long Pulse (About 1778µs)
SS: Short Space (About 889µs)
LS : Long Space (About 1778µs)
The resolution of the code is good as we’re working with interrupts.

The output of the IR receiver is connected to external interrupt pin (RB0) (interrupt on change) and every change in the pin status generates an interrupt and Timer1 starts ticking, Timer1 value will be used in the next interrupt, this means Timer1 measures the time between two interrupts which is pulse time or space time. Also, Timer1 interrupt is used to reset the decoding process in case of very long pulse or space.
Timer1 time step is 1µs (Timer1 increments every 1µs). If you use mcu frequency other than 8MHz, make sure to keep Timer1 time step to 1µs, otherwise time intervals have to be changed.

The microcontroller used in this example is PIC16F887, configuration words are:


  • In-Circuit Debugger disabled
  • Low voltage programming disabled
  • Fail-Safe Clock Monitor enabled
  • Internal/External Switchover mode enabled
  • Brown-out Reset (BOR) disabled
  • Data memory code protection disabled
  • Program memory code protection disabled
  • RE3/MCLR pin function is digital input, MCLR internally tied to VDD
  • Power-up Timer (PWRT) disabled
  • Watchdog Timer (WDT) disabled
  • INTOSCIO oscillator: I/O function on RA6/OSC2/CLKOUT pin, I/O function on RA7/OSC1/CLKIN
  • Flash Program Memory Self Write disabled
  • Brown-out Reset set to 4.0V

Full MPLAB XC8 code:

The following video shows how this project should work:

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