Real time clock with remote control and ST7735 TFT display – CCS C

Remote controlled real time clock using PIC18F4550 and DS1307
PIC18F4550 ST7735 TFT DS1307 RTC remote control circuit

(Some knowledge about RC-5 protocol is required)
This project shows how to build a remote controlled real time clock with TFT display using PIC18F4550 microcontroller.
In this project DS1307 RTC is used as a real time clock chip and the remote control is an IR (infrared) remote control which uses RC-5 communication protocol, this remote control is used to set time and date. The device used t display time and calendar is 1.8″ ST7735R (ST7735S) SPI TFT display.
To display the ST7735 TFT display with PIC18F4550 microcontroller we need a driver, this driver and some other details about this display can be fount at the following url:
ST7735 SPI TFT Display Driver for CCS PIC C compiler

And the post at the following link shows how to interface this display with PIC18F4550 microcontroller:
Interfacing PIC18F4550 with 1.8″ TFT display

Or simply you can download the ST7735 TFT driver from the following link:
ST7735 SPI TFT Display Driver

The method used to decode RC-5 signals is described in the following topic:
RC5 IR Remote Control Decoder with PIC12F1822 Microcontroller

The decoding process follows the state machine show below:

RC-5 protocol state machine

Where:
SP : Short Pulse (About 889µs)
LP : Long Pulse (About 1778µs)
SS: Short Space (About 889µs)
LS : Long Space (About 1778µs)
Basically there are 4 states: Mid1, Mid0, Start1 and Start0.

Components List:

  • PIC18F4550 Microcontroller
  • ST7735R (ST7735S) 1.8″ SPI TFT Display
  • DS1307 RTC Chip
  • RC-5 IR Remote Control
  • IR Receiver
  • 8MHz Crystal Oscillator
  • 32.768KHz Crystal Oscillator
  • 2 x 22pF Ceramic Capacitors
  • 47uF Capacitor
  • 3 x 10K Resistor
  • 5 x 1K Resistors
  • 3V Lithium Coin Cell Battery
  • +5V Power Supply Source
  • Breadboard
  • Jumper Wires

For the DS1307 RTC chip there are many topics in this blog talking about it and how to interface it with different types of PIC microcontrollers for example the topic at the url below:
Real time clock with PIC18F4550 and DS1307 RTC

Real time clock with remote control and ST7735 TFT display circuit:
The following image shows our project circuit schematic where the microcontroller runs with 8MHz external crystal oscillator.

Real time clock with remote control circuit

Real time clock with remote control and ST7735 TFT display CCS C code:
In this project the microcontroller runs with 8MHz external crystal oscillator and to make it runs at full speed which is 48MHz we have to use the following fuses:
#fuses NOMCLR HSPLL PLL2 CPUDIV1
Where: PLL2 enables the PLL and divide it by 2
and if for example the crystal oscillator frequency is 12MHz so we have to change PLL2 to PLL3 and so on.
CPUDIV1: No system clock postscaler
PIC18F4550 Microcontroller has only 1 MSSP module which can be configured to work as SPI module or I2C module. In this project we need SPI protocol for the TFT display and I2C for DS1307. Since the TFT display needs a high speed SPI interface, I used PIC18F4550 hardware SPI module to communicate with the TFT display and I implemented a software I2C protocol for DS1307, the following line is used to create a simple software I2C:
#use I2C(master, SDA = PIN_D3, SCL = PIN_D2)
So DS1307 SDA pin is mapped at RD3 and SCL at RD2.
The remote control used in this project is shown below with button codes. This IR remote control is just a TV remote control which use RC5 communication protocol:

LG TV remote control button codes

Only 3 buttons are used and the rest have no effect on the circuit.
The button codes displayed in the picture above are the address and command codes combined together. The RC-5 code message is 14 bit long, 2 start bits, a toggle bit, 5 bits as address and 6 bits as command. For example select button which has an address of 0 and command of 0x3B which gives a 16-bit number of 0x3B (toggle bit is neglected).
The toggle bit toggles between 0 and 1. Every time a button is pressed the toggle bit changes. If a button is pressed and kept pressing the toggle bit changes only at the first time and the remote control keep sending the same code of the pressed button with the same toggle bit.
From that I used the toggle bit to check if the select button is pressed again or kept pressing in order to avoid jumping from parameter to another and if you want to go from paramter to another you have to repress the select button.
For the other two buttons (up & down) the toggle bit is not used in order to speed up the setting of the parameters.
The output of the IR receiver is connected to RB2 pin which is external interrupt 2 pin. When the receiver receives an IR signal its output falls (goes form 5V to 0) which makes the microcontroller interrupts. When the mcu interrupts it jumps to interrupt routine ( void ext2_isr(void) ) and starts decoding the IR signal. Timer1 is used to measure pulses and spaces comes from the remote control. The microcontroller decodes the signal according to the state machine above. The interrupt is stopped during DS1307 reading or writing and also during sending data to TFT display.
The following code is tested with CCS PIC C compiler versions 4.068 and 5.051.

Real time clock with remote control and ST7735 TFT display video:
Project video ….

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