PIC18F4550 Real Time Clock with DS1307 and SSD1306 Display

Let’s continue the SSD1306 OLED display projects and now I’m going to build a simple real time clock with PIC18F4550 microcontroller and DS1307 real time clock chip, time and date are displayed on the SSD1306 display.
With the help of a 3V coin cell battery, the DS1307 RTC chip keeps the time running even if the main power supply is off. Time and date are set with two push buttons.

The SSD1306 OLED used in this post 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 …

To simplifies project circuit, the SSD1306 display and the DS1307 RTC chip are connected to the same I2C bus, always the PIC18F4550 microcontroller talks with one device only because their I2C slave addresses are different.

Related Projects:
The following topics may contain some useful information about the current project.
Interfacing PIC18F4550 with SSD1306 OLED
Real time clock with PIC18F4550 and DS1307 RTC – CCS C

Hardware Required:

  • PIC18F4550 microcontroller   —> datasheet
  • SSD1306 OLED display (128×64 Pixel)
  • DS1307 RTC   —>  datasheet
  • 32.768KHz crystal oscillator
  • 2 x 10K ohm resistor
  • 2 x push button
  • 3V coin cell battery
  • 5V power source
  • Breadboard
  • Jumper wires
  • PIC microcontroller programmer (PICkit 3, PICkit 4…)

PIC18F4550 Real time clock with DS1307 and SSD1306 display circuit:
The following image shows project circuit diagram.

PIC18F4550 SSD1306 DS1307 real time clock

(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.

In this project the PIC18F4550 runs with its internal oscillator @ 8MHz and MCLR pin function is disabled.

PIC18F4550 Real time clock with DS1307 and SSD1306 display C 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 DS1307 RTC and the SSD1306 OLED display share the same I2C bus, DS1307 I2C address is 0xD0 and SSD1306 display I2C address is 0x7A.

CCS C code:

Project simulation:
The video below shows the simulation of the project with Proteus ISIS. Note that simulation circuit is not the same as actual hardware circuit, project hardware circuit is shown above (don’t try to build your hardware circuit as shown in the simulation video, otherwise your circuit may not work or you’ll damage your components!).

Proteus simulation file download (for version 8.6 or higher):
PIC18F4550 + SSD1306 OLED + DS1307

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