PIC16F887 Interfacing with SSD1306 and DS1307 | mikroC Projects

This project shows how to build a real time clock using PIC16F887 microcontroller and DS1307 RTC (or DS3231) chip where time and date are displayed on OLED display with SSD1306 controller (128×64 Pixel).
With the help of a 3V coin cell battery the DS1307 keeps the time running even if the main power source is cut.
The compiler used in this project is mikroElektronika mikroC PRO for PIC.
A small video shows Proteus simulation of this project at the end of the post.

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 and I2C mode) such as soldering, placing jumpers …

To simplify project circuit, the SSD1306 OLED display and the DS1307 RTC chip share the same I2C bus, always the PIC16F887 microcontroller talks with one device only because their I2C slave addresses are different.

The PIC16F887 microcontroller has one hardware I2C module (MSSP module) with SDA on pin RC4 (#23) and SCL on pin RC3 (#18). The SDA pin of the MCU is connected to the SDA pin of the display (& DS1307 RTC) and the SCL pin of the MCU is connected to the SCL pin of the display (& DS1307 RTC).
The reset pin of the display is connected to pin RD4 (#27) of the microcontroller.

The SSD1306 OLED display DC pin is connected to VDD which means the I2C slave address of the display is 0x7A.

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 RB0 and RB1 pins are enabled in the code.

In this project the PIC16F887 microcontroller runs with its internal oscillator @ 8 MHz, MCLR pin is configured as an input pin.

PIC16F887 Interfacing with SSD1306 and DS1307 C code:
The following C code is for mikroC PRO for PIC compiler, it was tested with version 7.2.0.

The reset pin of the SSD1306 OLED display module is connected to pin RD4 of the microcontroller, this connection is defined as (there is no need for this connection if the display board has no rest pin):