Interfacing PIC18F4550 with Nokia 5110 LCD and DS3231 RTC

In the last PIC18F4550 microcontroller project, I’ve built a simple real time clock using DS1307 RTC and NOKIA 5110 graphical LCD (link is below) and in this project I’m going to show how to build a real time clock with chip temperature monitor using PIC18F4550 MCU, DS3231 RTC chip and the same LCD display (Nokia 5110).
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

and the following link shows how to interface PIC18F4550 MCU with Nokia 5110 LCD and DS1307:
Real Time Clock using PIC18F4550, Nokia 5110 LCD and DS1307

The DS3231 is more accurate than the DS1307 due to its built-in temperature sensor. It also (the DS3231) keeps time running if the main power source is down. It also uses I2C interface to communicate with the master device which is in this project PIC18F4550 microcontroller.

PIC18F4550 MCU with DS3231 and Nokia 5110 graphical LCD

Hardware Required:

  • PIC18F4550 microcontroller
  • Nokia 5110 LCD screen
  • DS3231 board    —->   DS3231 RTC datasheet
  • AMS1117 3V3 voltage regulator
  • 10 uF capacitor
  • 100 nF ceramic capacitor
  • 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 MCU with DS3231 RTC and Nokia 5110 LCD C code:
The following image shows project circuit schematic diagram.

PIC18F4550 Nokia 5110 GLCD DS3231 RTC with set buttons

All the grounded terminals are connected together.

The DS3231 board SDA pin and SCL pin 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 DS3231 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 DS3231 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, day of the week and chip temperature 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:

 

The result of this project should be the same as the one shown in the following video where Arduino UNO is used instead of the PIC18F4550 microcontroller:


Discover more from Simple Circuit

Subscribe to get the latest posts sent to your email.

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