Real Time Clock using PIC18F4550, Nokia 5110 LCD and DS1307

This post shows how to build a simple real time clock using PIC18F4550 microcontroller, Nokia 5110 graphical LCD and DS1307 RTC chip. Time and date are displayed on the Nokia 5110 LCD which has a resolution of 84 x 48 pixel and they could be set using two push buttons connected to the PIC18F4550 microcontroller.
The compiler used in this project is CCS PIC C.

To see how to interface the PIC18F4550 with the Nokia 5110 for the first time, visit the post below:
Interfacing PIC18F4550 MCU with NOKIA 5110 LCD

Hardware Required:

  • PIC18F4550 microcontroller
  • Nokia 5110 LCD screen
  • DS1307 RTC              —->    datasheet
  • 32.768 kHz crystal oscillator
  • AMS1117 3V3 voltage regulator
  • 10 uF capacitor
  • 100 nF ceramic capacitor
  • 2 x 10k ohm resistor
  • 5 x 3.3k ohm resistor
  • 5 x 2.2k ohm resistor
  • 2 x push button
  • 3V coin cell battery
  • 5V power source
  • Breadboard
  • Jumper wires

PIC18F4550 Clock with Nokia 5110 LCD and DS1307 circuit:
The following image shows project circuit schematic diagram.

PIC18F4550 DS1307 Nokia 5110 3310 LCD real time clock circuit

All the grounded terminals are connected together.

DS1307 SDA pin (#5) and SCL pin (#6) are connected to PIC18F4550 RD4 (#27) and RD5 (#28) respectively.

The two push buttons B1 and B2 are for setting time and date. The two buttons are connected to PIC18F4550 pin RB4 (#37) and pin RB3 (#36) respectively for B1 and B2.

In this project the PIC18F4550 uses its internal oscillator and MCLR pin function is disabled.

PIC18F4550 Clock with Nokia 5110 LCD and DS1307 C code:
The C code below is for CCS C compiler, it was tested with version 5.051.

To be able to compile project C code, a driver for the Nokia 5110 LCD is required, download link is below. After you download the driver file which named NOKIA5110.c, add it to your project folder:
Nokia 5110 LCD driver for CCS C compiler

Connection of LCD reset, chip select and data/command pins are defined in the code as:

I2C Bus (software) is initialized in the code as shown below with SCL mapped to pin RD5 and SDA to pin RD4 (required for the DS1307 RTC chip):

Functions used in the code:
int1 debounce (): this function is for button B1 debounce, returns 1 if button is debounced.

void day_display(): displays day of the week (Monday, Tuesday …) on the LCD.

void RTC_display(): displays time, date and day of the week on the LCD. This function calls the previous one for displaying the day of the week.

void wait(): this function is just a delay of 500 ms except that it can be interrupted by the two push buttons (B1 and B2).

int8 edit(int8 x_pos, int8 y_pos, int8 parameter): this function is for setting the real time clock, returns the edited parameter.

Rest of code is described through comments!

Full CCS C code:

My simple protoboard circuit gave the following result:

PIC18F4550 with DS1307 RTC, Nokia 5110 LCD and set buttons

Proteus simulation of this project should give the same result as shown in the following video where Arduino UNO is used instead of the PIC18F4550 microcontroller:

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