Real time clock with PIC12F1822, SSD1306 OLED and DS3231 RTC

This post shows how to build a real time clock/calendar with temperature monitor using PIC12F1822 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 PIC12F1822 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 PIC12F1822 with SSD1306 OLED
Interfacing PIC12F1822 with DS3231/DS1307 and I2C LCD
PIC12F1822 + DS3231 + Remote Control with CCS C compiler

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 …

PIC12F1822 SSD1306 DS3231 real time clock with set buttons

Hardware Required:

  • PIC12F1822 microcontroller
  • SSD1306 OLED display (128×64 Pixel)
  • DS3231 board   —   DS3231 RTC datasheet
  • 2 x push button
  • 3V coin cell battery
  • 5V power source
  • Breadboard
  • Jumper wires

Real time clock with PIC12F1822, SSD1306 OLED and DS3231 circuit:
The following image shows project circuit schematic diagram.

PIC12F1822 DS3231 SSD1306 real time clock with set buttons

(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 RA5 (#2) and B2 is connected to pin RA4 (#3). Internal pull-ups for the two input pins are enabled in the code.

PIC12F1822 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 PIC12F1822 microcontroller uses with its internal oscillator @ 32 MHz, MCLR pin is configured as an input pin.

Real time clock with PIC12F1822, SSD1306 OLED and DS3231 C code:
The C code below is for CCS C compiler, it was tested with version 5.051 and version 5.079.

Version 5.051:
Used RAM: 44%
Used ROM: 98%

Version 5.079:
Used RAM: 41%
Used ROM: 98%

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:

The hardware circuit of this project should be the same as what shown in the following video where PIC16F877A MCU is used:

Leave a Reply

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