Real Time Clock with Temperature Monitor and Color TFT – mikroC

After I successfully interfaced the PIC16F887 microcontroller with ST7735R (ST7735S) SPI color TFT module, now let’s see how to build a real time clock with temperature monitor using PIC16F887 MCU, ST7735R TFT and DS3231 RTC module. The compiler used in this project is mikroC PRO for PIC.

Related Project:
Interfacing PIC microcontroller with ST7735R SPI TFT – mikroC Projects

Hardware Required:

  • PIC16F887 microcontroller   —> datasheet
  • DS3231 board   —>  DS3231 datasheet
  • ST7735R (ST7735S) TFT screen
  • 20 MHz crystal oscillator
  • 2 x 22 pF ceramic capacitor
  • 5 x 1K ohm resistor
  • 2 x push button
  • 3V coin cell battery
  • Power source with 5V
  • Breadboard
  • Jumper wires
  • PIC programmer (PICkit 2, PICkit 3…)

Real time clock with temperature monitor and color display circuit:
Project circuit schematic diagram is shown below.

PIC16F887 DS3231 ST7735S color TFT circuit

(All grounded terminals are connected together)

In the circuit there are 2 pushbuttons (B1 & B2) connected to pins RB2 and RB3 of the PIC16F887 microcontroller 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) for pins RB2 and RB3 which means there is no need for external pull up resistors. Also, there is no pull-up resistor connected to MCLR pin because it is configured to work as a digital input pin (in the software).

SCL and SDA lines of the DS3231 are connected to RB0 and RB1 pins of the PIC16F887 respectively.

In this project I used 20MHz crystal oscillator which is the maximum speed of the PIC16F887, this gives the highest SPI data transfer rate (5Mbit/s). Lower crystal frequencies can be used or even the internal oscillator of the microcontroller.

Real time clock with temperature monitor and color display C code:
To be able to compile the mikroC code below we need a small file named ST7735_TFT.c , this file is the driver (library) of this type of TFT. The library file download link can be found at the end of this topic:
ST7735R SPI TFT driver for mikroC PRO for PIC

After downloading the driver file just put it in the project folder.

Since the PIC16F887 has one MSSP module (Master Synchronous Serial Port module) which can operate in SPI mode or I2C mode, also they share the same pins, I used software I2C to communicate between the master device (the microcontroller) and the slave device (DS3231).

mikroC PRO for PIC compiler has a nice library for software I2C, SCL and SDA connections can be configured as:

// Software I2C connections (needed for DS3231 RTC)
sbit Soft_I2C_SCL at RB0_bit;
sbit Soft_I2C_SDA at RB1_bit;
sbit Soft_I2C_SCL_Direction at TRISB0_bit;
sbit Soft_I2C_SDA_Direction at TRISB1_bit;
// End Software I2C connections

and it can be initialize with the function: Soft_I2C_Init() .

The software I2C library has a fixed clock frequency of 20KHz, the DS3231 can work with this speed.

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

Configuration words:
CONFIG1: 0x2CD2
CONFIG2: 0x0700

Full mikroC code:

The result of this project should be the same as the one shown in the two videos below where PIC16F877A is used with CCS C compiler.

The first video shows a simple hardware circuit of the project:

and the second video shows the simulation of the project with Proteus:

PIC16F887 + DS3231 RTC + ST7735S TFT Proteus simulation file download:
Download


Discover more from Simple Circuit

Subscribe to get the latest posts sent to your email.

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