Interfacing PIC MCU with Nokia 5110 LCD | mikroC Projects

This PIC MCU project shows how interface PIC18F46K22 microcontroller with Nokia 5110 (Nokia 3310) graphical LCD screen. In this project I’m going to use mikroC PRO for PIC compiler.
The name Nokia 5110 (3310) comes from Nokia 5110 (or Nokia 3310) mobile phone. The Nokia 5110 LCD has a controller named PCD8544, it 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 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.

Nokia 5110 driver for mikroC compiler:
To simplify the interfacing C code, I wrote a simple driver (library) for the Nokia 5110 LCD (PCD8544 controller).
This small driver and graphics library allows us to print texts, draw lines, circles and many other function (listed below). This library is just a .C file, its full name (with extension): NOKIA5110.C. It may be installed by adding it to mikroC project folder.

The Nokia 5110 LCD library can be downloaded from the following URL:
Nokia 5110 LCD library for mikroC compiler

The connection of the LCD to the microcontroller is defined in the main code before including the library source file.
Example:

In this example all the 5 pins of the LCD module are defined.
The LCD_RST (reset) pin connection is optional, if it’s not used then it must be connected to VCC (+3.3V) because it’s active low.
The LCD_CS (chip select, or chip enable) pin connection is also optional, it has to be connected to GND if it’s not used (active low).

If the LCD clock and data pins (LCD_CLK and LCD_DAT) are defined, the library will automatically use software SPI. If they are not defined it will use hardware SPI1 module, and if the following line is defined the library will use hardware SPI2 module:

If hardware SPI module (SPI1 or SPI2) is used, it must be initialized before the initialization of the LCD (using SPIx_Init or SPIx_Init_Advanced where x 1 or 2).

The direction pins of the LCD may be defined as shown below:

Nokia 5110 Library Functions:
This is a list of library functions.

LCD_Begin(): this function initializes the Nokia 5110 LCD.
LCD_SetContrast(con): sets the contrast of the display where: 0 <= con <= 63 .
LCD_Display(): prints data buffer on the display, must be called after any draw action.

LCD_Clear(): clears the whole LCD.
LCD_Fill(): fills the whole LCD (writes all LCD pixels).
LCD_SetRotation(rot): sets rotation setting for the display, rot may be in the range [0, 3].
LCD_GetRotation(): returns rotation setting of the display (value from 0 to 3).
LCD_GetWidth(): returns the width of the display, accounting for the current rotation.
LCD_GetHeight(): returns the height of the display, accounting for the current rotation.

LCD_TextSize(t_size): sets text size.
LCD_TextColor(t_color, t_bg): sets text color where t_color is text color and t_bg is background color. Both variables are of type bool (may be 1 or 0). Black color is defined as 1 (true) and white is defined as 0 (false).
LCD_GotoXY(x, y): moves cursor to position (x, y), x and y are in pixel.
LCD_TextWrap(w): sets text wrap, if w = 1 (true) text wrap is enabled (default), if w = 0 (false) text wrap is disabled.
LCD_PutC(c): prints a single character c on the LCD.
LCD_PutCustomC(*c): prints a custom character c on the display with 5×7 dimension (same as built-in font dimension), this character must be stored in ROM space.
LCD_Print(*s): prints a string s (text) on the LCD.
LCD_Invert(inv): inverts the display, inv may be 1 or 0.

LCD_DrawPixel(x, y, color): draws one pixel on the screen, x and y are the coordinates in pixel.
LCD_DrawLine(x0, y0, x1, y1, color): draws a line from (x0, y0) to (x1, y1).
LCD_DrawHLine(x, y, w, color): draws a horizontal line from (x, y) with width of w.
LCD_DrawVLine(x, y, h, color); draws a vertical line from (x, y) with height of h.

LCD_DrawRect(x, y, w, h, color): draws a rectangle from (x, y) with width w and height h.
LCD_FillRect(x, y, w, h, color): fills a rectangle from (x, y) with width w and height h.
LCD_DrawRoundRect(x, y, w, h, r, color): draws round rectangle from (x, y) with width w, height h and radius r.
LCD_FillRoundRect(x, y, w, h, r, color): fills round rectangle from (x, y) with width w, height h & radius r.

LCD_DrawTriangle(x0, y0, x1, y1, x2, y2, color): draws a triangle with points (x0, y0), (x1, y1) and (x2, y2).
LCD_FillTriangle(x0, y0, x1, y1, x2, y2, color): fills a triangle with points (x0, y0), (x1, y1) and (x2, y2).

LCD_DrawCircle(x0, y0, r, color): draws a circle from (x0, y0) with radius r.
LCD_FillCircle(x0, y0, r, color): fills a circle from (x0, y0) with radius r.
LCD_DrawCircleHelper(x0, y0, r, cornername, color): draws a circle helper from (x0, y0) with radius r and cornername.
LCD_FillCircleHelper(x0, y0, r, cornername, delta, color): fills a circle helper from (x0, y0) with radius r and cornername.

LCD_ROMBMP(x, y, *bitmap, w, h, color): draws a bitmap located in ROM.
LCD_RAMBMP(x, y, *bitmap, w, h, color): draws a bitmap located in RAM.

The variable color is of type bool (may be 1 or 0). Black color is defined as 1 (true) and white is defined as 0 (false).

Interfacing PIC18F46K22 MCU with NOKIA 5110 LCD:
This is a simple example that shows how to use Nokia 5110 LCD library for mikroC compiler.

PIC18F46K22 MCU with Nokia 5110 LCD circuit

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.

PIC18F46K22 Nokia 5110 LCD interfacing circuit

All the grounded terminals are connected together.

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

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 steps down 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.2.0.
This example is from Adafruit Nokia 5110 driver for Arduino (pcdtest.ino) with some modifications.

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

Testing example hardware circuit gave me a result near to what’s shown in this video where Arduino UNO board is used instead of the PIC18F46K22 microcontroller:

Proteus simulation:
We can simulate this project using Proteus software. Simulation result should be near to the one shwn in this video:

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

PIC Projects where Nokia 5110 LCD is used:

Leave a Reply

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