Interfacing PIC18F4550 with DS3231 RTC and SSD1306 display

This post shows how to build a real time clock/calendar and temperature monitor using PIC18F4550 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.
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 PIC18F4550 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 OLED address is 0x7A.
In the circuit there are two push buttons for setting time and date of the real time clock.

Related Projects:
Interfacing PIC18F4550 with SSD1306 OLED
PIC18F4550 Real time clock with DS1307 and SSD1306 display
Real time clock & calendar with PIC18F4550 and DS3231 – CCS C

Hardware Required:

  • PIC18F4550 microcontroller
  • DS3231 board   —   DS3231 RTC datasheet
  • SSD1306 OLED (I2C mode)
  • 2 x push button
  • 3V coin cell battery
  • Power source with 5VDC
  • Breadboard
  • Jumper wires

PIC18F4550 microcontroller with DS3231 RTCC and SSD1306 OLED display

The Circuit:
Project circuit diagram is shown by the following image.

PIC18F4550 SSD1306 DS3231 RTC SSD1306 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 RB4 (#37) and B2 is connected to pin RB3 (#36). Internal pull-ups for PORTB pins are enabled in the code.

PIC18F4550 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 PIC18F4550 runs with its internal oscillator @ 8MHz and MCLR pin function is disabled.

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 SSD1306OLED.C, for more information about this driver, visit the following post:
SSD1306 OLED Library for CCS C compiler

It can be downloaded also from the link below:
SSD1306 OLED Library download

after the download, add the driver file to 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:

Project video:

Leave a Reply

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