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.

Related Projects:
Interfacing PIC microcontroller with SSD1306 OLED | mikroC Projects

Hardware Required:

  • PIC16F887 microcontroller
  • 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

PIC16F887 Interfacing with SSD1306 and DS1307 circuit:
Project circuit schematic diagram is shown below.

PIC16F887 with DS1307 RTC and SSD1306 OLED - SSD1306 DS1307

(All grounded terminals are connected together)

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.

To be able to compile the C code below with no error, a driver (& library) for the SSD1306 OLED display is required, it’s full name is SSD1306.C, download link is below:
SSD1306 OLED display driver for mikroC compiler

after the download, add the driver file (SSD1306.C) to project 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 (default address).

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):

Full mikroC code:
Configuration words:
CONFIG1 = 0x2CD4
CONFIG2 = 0x0700

The simulation of this project using Proteus should be similar to what’s shown in the following video where PIC16F877A microcontroller is used:

Leave a Reply

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