RF Transmitter and receiver system using PIC16F887 – CCS C

Topics related to this post:
LED Blink with PIC16F887 microcontroller
PIC16F887 Timers and Interrupts

This post shows the making of a simple 4-channel RF (Radio Frequency) remote control system based on PIC16F887 microcontroller.
The RF remote control system consists of two parts, transmitter part and receiver part. Both parts are based on the same microcontroller type which is PIC16F887. The transmitter circuit contains an RF transmitter which is responsible for transmitting RF signals while the receiver circuit contains an RF receiver which receives the RF signals transmitted by the transmitter circuit. Module frequency can be 315MHz or 433MHz. I used the module shown in the picture below:

433MHz RF transmitter and receiver modules

The RF transmitter can be powered from 3 to 12V depending on the range required (more voltage —> more transmission range).

Communication protocol:
In this RF project NEC protocol is used to send data from the transmitter circuit to the receiver circuit. More details about the NEC protocol and how to decode it using PIC16F887 in the following topic:
NEC Protocol decoder with PIC16F887 microcontroller

The difference between the IR and RF receivers is that the IR receiver output is logic 0 (0V) while it receives an IR pulse and its idle state is logic 1 (5V). For the RF receiver the situation is reversed, the idle state is logic 0 and the active sate is logic 1.

Hardware Required:
1 – RF Transmitter circuit:

  • PIC16F887 microcontroller
  • 433MHz / 315MHz RF transmitter
  • 4 x push button
  • 5V voltage source
  • Breadboard
  • Jumper wires

2 – RF Receiver circuit:

  • PIC16F887 microcontroller
  • 433MHz / 315MHz RF receiver
  • 100µF capacitor
  • 4 x LED
  • 4 x 470 ohm resistor
  • 5V voltage source
  • Breadboard
  • Jumper wires

RF Transmitter and receiver system using PIC16F887 circuit:
1 – RF Transmitter circuit:

RF remote control transmitter circuit

In the RF transmitter circuit there are 4 push buttons connected to RB0, RB1, RB2 and RB3, each button sends a different RF code via the RF transmitter where the RF transmitter data pin is connected to RB4.
The internal pull-ups of PORTB input pins are enabled in the software.
In this project PIC16F887 uses its internal oscillator and MCLR pin function is disabled.
2 – RF Receiver circuit:

RF remote control receiver circuit

In the receiver circuit there are 4 LEDs, these LEDs are connected to pins RD0, RD1, RD2 and RD3 through 470 ohm resistors. Each LED is controlled from a push button in the RF transmitter circuit.
The RF receiver data pin is connected to pin RB0 which is the external interrupt pin of the PIC16F887. A 100µF capacitor should be added between VCC and GND of the RF receiver.
In this circuit also the PIC16F887 uses its internal oscillator and MCLR pin function is disabled.

RF Transmitter and receiver system using PIC16F887 C code:
The following C code are for CCS PIC C compiler.

1 – RF Transmitter code:
The first code is for the RF transmitter circuit microcontroller. The transmitter circuit has 4 push buttons: B1, B2, B3 and B4. Each button sends a code through the RF transmitter as follows (32-bit codes):
B1 ——–> 0x00FF00FF
B2 ——–> 0x00FF807F
B3 ——–> 0x00FF40BF
B4 ——–> 0x00FF20DF
The full C code is below.

2 – RF Receiver code:
The output of the RF receiver is connected to the external interrupt pin (RB0) and this interrupt is used to detect any incoming signal (even noise).
Timer1 module is used to measure pulse and space widths and also Timer1 interrupt is used to reset the decoding process in case of very long pulse or space ( > 65.535 ms). Timer1 is configured to increment every 1µs using the following line:
setup_timer_1( T1_INTERNAL | T1_DIV_BY_2 );
The microcontroller will not do any thing until the complete decoding process is completed and at the end of the decoding process the variable code_ok is set ( = 1).
The variable nec_state is used to define the decoding process state, totally there are 5 states:
State 0: beginning of decoding process which is the beginning of 9ms pulse.
State 1: start of 4.5ms space
State 2: start of 560µs pulse
State 3: start of 560µs pulse or 1680 space
State 4: end of 560µs pulse or 1680 space
The full C code of the RF receiver is below.

The following video shows our example in hardware circuits:

4 comments

  1. Hello,
    Nice information,,,
    Which software used for complie,,,this software,,,and any coad for proton compiler…😄

Leave a Reply

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