PIC16F877A with DS3231 RTC and 128×160 TFT

This topic shows how to build a real time clock with temperature monitor using PIC16F877A microcontroller, DS3231 RTC chip and ST7735R (ST7735S) 128×160 color TFT display. CCS C compiler is used in this example. Also a small video shows Proteus simulation of this project.

PIC16F877A microcontroller with ST7735 TFT and DS3231 RTC

To build this project we need a driver for the ST7735 TFT screen which can be found in the post below:
ST7735 SPI TFT Display Driver for CCS C compiler

Previously I interfaced the PIC16F877A microcontroller with the DS3231 and the ST7735 TFT modules, project links are below:
Real time clock and calendar using DS3231 and PIC16F877A – CCS C
PIC16F877A + DS3231 with alarms and temperature monitor – CCS C
ST7735 1.8″ TFT display with PIC16F877A example – CCS C

Components Required:
To build this project we need the following components.

  • PIC16F877A microcontroller
  • DS3231 board
  • ST7735R (ST7735S) TFT screen
  • 20 MHz crystal oscillator
  • 2 x 22 pF ceramic capacitor
  • 10k ohm resistor
  • 5 x 1K ohm resistor
  • 2 x push button
  • 3V coin cell battery
  • Power source with 5V
  • Breadboard
  • Jumper wires

PIC16F877A with DS3231 RTC and 128×160 TFT circuit:
Project circuit schematic diagram is shown below.

PIC16F877A DS3231 ST7735 TFT real time clock with buttons

All grounded terminals are connected together.

In the circuit there are 2 push buttons (B1 & B2) connected to PIC16F877A pins RB2 and RB3 respectively, the two push buttons are used to set time and date parameters (minutes, hours, day of the week, date, month and year). Button B1 selects the parameter and B2 increments the selected parameter.

In this project PORTB pull-ups are enabled (in the software) which means there is no need for external pull up resistors for pins RB2 and RB3. The microcontroller runs with 20MHz crystal oscillator (5 MIPS).

PIC16F877A with DS3231 RTC and 128×160 TFT C code:
The C code below was tested with CCS C compiler version 5.051 with no error and no warning!

ST7735 TFT driver for CCS C compiler is required and without it we can not compile the code, driver download link can be found in this post:
ST7735 SPI TFT Display Driver for CCS C compiler

After you download the driver (ST7735_TFT.c) just put it in your project folder or CCS C compiler drivers folder.

Since the PIC16F877A has one MSSP module (Master Synchronous Serial Port module) which can operate in SPI mode or I2C mode, I used software I2C to communicate between the master device (the microcontroller) and the slave device (DS3231). Software I2C is initialized using the function below:
#use I2C(master, SCL = PIN_B0, SDA = PIN_B1)

So, I used the MSSP in SPI mode for faster data transfer between the microcontroller and the ST7735 TFT display. Software SPI can be used but its very slow compared to hardware SPI.

The video below shows a simple protoboard circuit of the project:

and the following video shows Proteus simulation where DS3232 is used instead of the DS3231:

Proteus simulation file download:
Proteus simulation file can be downloaded from the link below, use it with version 8.6 or higher.


Leave a Reply

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