Interfacing PIC16F877A with SSD1306 OLED and DS3231 RTC

This post shows how to build a real time clock/calendar with temperature monitor using PIC16F877A microcontroller, DS3231 RTCC and SSD1306 OLED display. Time and date are set with two push buttons and they are displayed on the SSD1306 OLED screen (128×64 Pixel).
The DS3231 has a buit-in temperature sensor which means we can use it for measuring the chip temperature.

The DS3231 is more accurate than the DS1307 due to its built-in temperature sensor. It also (the DS3231) keeps the time running if the main power source is down (with the help of a coin cell battery). It also uses I2C interface to communicate with the master device which is in this project PIC16F877A microcontroller. This means the DS3231 and the SSD1306 OLED screen share the same I2C bus. Even they share the same bus but at any time the microcontroller ‘speaks’ with 1 device only depending on the address sent. The DS3231 RTC address is 0xD0 (the same as the DS1307 address) and the SSD1306 address is 0x7A.
In the circuit there are two push buttons for setting time and date of the real time clock.

Related Projects:
The following topics may contain some useful information about the current project.
Interfacing PIC16F877A with SSD1306 OLED display
Real time clock with PIC16F877A, SSD1306 OLED and DS1307
Real time clock and calendar using DS3231 and PIC16F877A

The SSD1306 OLED used in this project is configured to work in I2C mode, some SSD1306 OLED boards may require a small hardware modifications (to select between SPI mode or I2C mode) such as soldering, placing jumpers …

Hardware Required:

  • PIC16F877A microcontroller
  • SSD1306 OLED display (128×64 Pixel)
  • DS3231 board   —   DS3231 RTC datasheet
  • 8 MHz crystal oscillator
  • 2 x 22pF ceramic capacitor
  • 10k ohm resistor
  • 2 x push button
  • 3V coin cell battery
  • 5V power source
  • Breadboard
  • Jumper wires

PIC16F877A with DS3231 RTC and I2C SSD1306 OLED display

The Circuit:
The following image shows project circuit diagram.

PIC16F877A SSD1306 DS3231 real time clock with OLED display

(All grounded terminals are connected together)

The two push buttons B1 and B2 are for setting time and date. Button B1 is connected to pin RB0 (#33) and B2 is connected to pin RB1 (#34). Internal pull-ups for PORTB pins are enabled in the code.

PIC16F877A microcontroller, DS3231 board and SSD1306 display board are supplied with 5V source between their VDD (or VCC) pin and GND pin.

In this project the PIC16F877A microcontroller runs with crystal oscillator of 8MHz.

The Code:
The C code below is for CCS C compiler, it was tested with version 5.051.

To be able to compile the C code below with no error, a driver for the SSD1306 OLED display is required, it’s name is SSD1306.C, its download link is below:
SSD1306 OLED display driver

after the download, add the driver file to the project folder or CCS C compiler drivers folder.

The DS3231 RTC and the SSD1306 OLED display share the same I2C bus, DS3231 I2C address is 0xD0 and SSD1306 display I2C address is 0x7A.

CCS C code:

PIC16F877A + SSD1306 OLED + DS3231 Project video:


Discover more from Simple Circuit

Subscribe to get the latest posts sent to your email.

1 thought on “Interfacing PIC16F877A with SSD1306 OLED and DS3231 RTC”

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