PIC MCU with Nokia 5110 LCD – Graphics Test Example | mikroC Projects

This PIC MCU project shows how to interface Microchip PIC18F46K22 microcontroller with Nokia 5110 (Nokia 3310) graphical LCD screen.
The name Nokia 5110 (3310) comes from Nokia 5110 (or Nokia 3310) mobile phone. The Nokia 5110 LCD has a controller named PCD8544. This LCD is similar to the Nokia 5110 mobile phone LCD, it uses SPI interface protocol with maximum clock frequency of 4MHz, it requires 5 control pins (at most), it’s low cost and easy to use.

The compiler used in this project is mikroElektronika mikroC PRO for PIC.
SPI: Serial Peripheral Interface.

The resolution of this LCD is 84 x 48 which means it has 4032 pixels. This module works with 3.3V only and it doesn’t support 5V (it’s not 5V tolerant), this means interfacing it with 5V microcontroller such as PIC18F46K22 MCU may require voltage level shifter.

The Nokia 5110 LCD module is shown below:

Nokia 5110 LCD module

This module has 8 pins (from left to right): RST (reset), CE (chip enable), DC (or D/C: data/command), Din (data in), Clk (clock), VCC (3.3V), BL (back light) and Gnd (ground).

The pins which may be connected to the microcontroller are: RST, CE, DC, Din and Clk.

Hardware Required:

  • PIC18F46K22 microcontroller   —->  datasheet
  • Nokia 5110 (3310) LCD module
  • AMS1117 3V3 voltage regulator
  • 10 uF capacitor
  • 100 nF ceramic capacitor
  • 5 x 3.3k ohm resistor
  • 5 x 2.2k ohm resistor
  • 5V source
  • Breadboard
  • Jumper wires

Interfacing PIC18F46K22 MCU with Nokia 5110 LCD circuit:
The following image shows example circuit schematic diagram.

The Nokia 5110 which is shown in the circuit diagram has 8 pins (from left to right): RST (reset), CE (chip enable), DC (or D/C: data/command), Din (data in), Clk (clock), VCC (3.3V), BL (back light) and Gnd (ground).

PIC18F46K22 Nokia 5110 LCD interfacing circuit

All the grounded terminals are connected together.

The Nokia 5110 LCD works with 3.3V only (power supply and control lines). The LCD module is supplied with 3.3V which comes from the AMS1117 3V3 voltage regulator, this regulator converts the 5V into 3.3V (supplies the LCD controller PCD8544 with regulated 3V3).

All PIC18F46K22 microcontroller output pins are 5V, connecting a 5V pin directly to the Nokia 5110 LCD may damage its controller circuit!
To connect the PIC18F46K22 to the LCD module, I used voltage divider for each line. That means there are 5 voltage dividers. Each voltage divider consists of 2.2k and 3.3k resistors, this drops the 5V into 3V which is sufficient.

So, the Nokia 5110 LCD pins are connected to PIC18F46K22 MCU as follows (each one through voltage divider):
RST (reset) pin is connected to pin RD0 (#19),
CE (chip enable) pin is connected to pin RD1 (#20),
DC (data/command) pin is connected to pin RD2 (#21),
DIN (data in)  pin is connected to pin RD3 (#22),
CLK (clock) pin is connected to pin RD4 (#27).

VCC and BL are connected to AMS1117 3V3 regulator output pin and GND is connected to circuit ground (0V).

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

Interfacing PIC18F46K22 MCU with Nokia 5110 LCD C code:
The following C code is for mikroC PRO for PIC compiler, it was tested with version 7.6.0.

To be able to compile project C code with no error, 2 libraries are required:
The first library is a driver for the Nokia 5110 LCD (PCD8544 controller), its full name (with extension) is PCD8544.c, download link is below:
Nokia 5110 LCD library for mikroC compiler

The second library is graphics library, its full name is GFX_Library.c, download link is the one below:
Graphics library for mikroC compiler

after the download of the 2 library files, add both of them to the project folder.

The default connection setting of the Nokia 5110 LCD (PCD8544) library is hardware SPI1 module (SPI1_Init(); must be called before initiating the LCD). Instead of hardware SPI1 module, software SPI or hardware SPI2 module can be used.

If LCD data pin (LCD_DAT) and clock pin (LCD_CLK) are defined then the library will automatically use software SPI.
example (respectively, LCD_DAT and LCD_CLK are connected to RD3 and RD4):
#define LCD_DAT RD3_bit
#define LCD_CLK RD4_bit

If the line below is defined then the library will use hardware SPI2 module:
#define LCD_HARD_SPI2
and SPI2_Init(); function must be called before initiating the LCD.

Hints:
The 2 library files are included in the main code as shown below:

Connections of LCD pins with the microcontroller are defined as (software SPI is used):

And the LCD is initialized as:

Rest of code is described through comments.

Full mikroC code:

My breadboard circuit result is shown by the following video:

Proteus simulation:
This example works with Proteus simulation software since it contains the Nokia 5110 (3310) LCD library. The video below shows the simulation result:

Proteus simulation file download link is below, use version 8.6 or higher to open it:
PIC18F46K22 and Nokia 5110 Proteus simulation

Leave a Reply

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