Fads to Obsessions and Beyond...




Free domain for life, exceptional technical support, website transfer

Nokia 5110 LCD

A Nokia 5110 LCD (84x48 LCD module using PCD8544 display chip) is interfaced to a PIC16F876A microcontroller. Basic LCD screen display functions are demonstrated.

The Nokia 5110 is a basic monochrome graphic LCD screen originally manufactured for use in cell phones (1). This component is now largely superceded for such applications, but due to previous high manufacturing volumes is widely available (cheaply via ebay/China) for hobbyists etc. These LCD screens are available for approximately $3 (or less if buying a number together) which is similar/less than the typical HD44780 based 16x2 line LCD module. The typical HD44780 based LCD is much larger and consumes more power. The Nokia 5110, using a "6x8" font (which is quite readable) enables effectively 14 characters by 6 lines of output, and additionally, allows the ability to display graphics such as bitmaps, produce graphs etc. The Nokia 5110 consumes very little power making battery powered applications amenable. The downside is the additional ROM/RAM required by the PIC microcontroller (or similar) to interface the Nokia 5110.

It uses the PCD8544 controller, which is the same used in the Nokia 3310 LCD. The PCD8544 is a low power CMOS LCD controller/driver, designed to drive a graphic display of 48 rows and 84 columns. All necessary functions for the display are provided in a single chip, including on-chip generation of LCD supply and bias voltages, resulting in a minimum of external components and low power consumption. The PCD8544 interfaces to microcontrollers through a serial bus (SPI) interface. The component is typically available through ebay from various resellers already mounted on a PCB with 6-pin connector only requiring connection to the target circuit/application. Some features of the component from the datasheet:

    • Single chip LCD controller/driver
    • 48 row, 84 column outputs
    • Display data RAM 48 × 84 bits
    • Serial interface maximum 4.0 Mbits/s
    • Logic supply voltage range VDD to VSS 2.7V to 3.3V
    • Limiting values: supply voltage VDD: 7V
    • Limiting values: all input voltages: VDD + 0.5V

Hardware/Interfacing

The units purchased/tested were shipped already mounted on a PCB, so only the connections to supply electricity and control lines were necessary to attach. This is discussed in the "Circuit Details" section. The major item to note is the requirement for a 3.3 volt supply. There are many sites that advise that the Nokia 5110 can be successfully interfaced using 5v (convenient for the typical microcontroller), however, there are similar number of sites that advise against this (including the datasheet). Since a 3.3v supply is not particularly problematic (e.g. using readily available/cheap LM1086 linear regulator or similar, or even diodes and/or resistor divider network etc if funds really tight!) the Nokia 5110 is used with 3.3v during this testing.

This 3.3v supply for the Nokia 5110 also extends to the control line voltages. Since the PIC 16F876A used here (and many similar PIC microcontrollers) produces nominally 5v on the output pins, a voltage level converter is required. This could again be a resistor divider network (if funds particularly problematic), but since components such as CD4050 hex non-inverting buffer IC's are readily available (at time of writing, can purchase 10x CD4050 for ~$3 from ebay/Hong Kong) this has been used between the PIC 16F876A and the Nokia 5110. See the "Circuit Details" and "Schematic Diagram" Sections for full details.

Software/Interfacing

There are a number of software libraries available for interfacing the Nokia 5110 to various microcontrollers. The software used is based upon that produced by Michel Bavin and downloaded from the CCS Compiler discussion forum (2). The actual code is discussed in the Experimental Results section (with download links). However, some initial background about the Nokia 5110/PCD8544 controller from the datasheet in order to understand instruction registers, memory addressing etc is given in the following paragraphs.

Display RAM Addressing

The PCD8544 display RAM consists of 84 by 48 bits (X versus Y address), but the Y address is in the form of one byte at a time. This effectively then gives 84 columns (0 to 83 "X addresses") and 6 rows (0 to 5 "Y addresses"). This means you cannot address each pixel on the LCD screen individually. There are two "addressing" modes, vertical and horizontal, and the current X and Y address pointers within the PCD8544 are automatically incremented when data bytes are clocked-in. In horizontal mode, this means each byte is input into PCD8544 display RAM (LSB first) at the current X and Y position, and then the X address is automatically incremented. When the X address overflows at position 83, then the Y address is incremented (ie the next row is used). This is depicted in the following diagram. Conversely, with vertical addressing, the Y address is automatically incremented after each data byte first. When the Y address overflows (ie position 5) then the X address is incremented.

  • Nokia 5110/PCD8544 RAM Format/Addressing

    Nokia 5110/PCD8544 RAM Format/AddressingNokia 5110/PCD8544 RAM Format/Addressing

    Silver Membership registration gives access to full resolution diagrams.

    Nokia 5110/PCD8544 RAM Format/Addressing

Since typically strings of letters/numbers are being displayed, the horizontal mode is most convenient. That is, each letter/number will automatically increment from left to right on the LCD screen. The addressing mode, along with a number of other allowable instructions, is set via a serial data stream with the bit pattern of each byte differentiating which instruction/options are being set.

Instruction Set

The instruction set consists of two modes:

  • if D/C signal/pin is set LOW the byte is interpreted as a Command (see following diagram). In turn, there are two types of Command:
    • Basic Instruction Set - if "H" i.e. DB0, of the command byte=0
    • Extended Instruction Set - if "H" i.e. DB0, of the command byte=1
  • if D/C signal/pin is set HIGH the byte is interpreted as Data for PCD8544 RAM display
  • Graph 1: Calibration - volts display

    Nokia 5110/PCD8544 Instruction SetNokia 5110/PCD8544 Instruction Set

    Silver Membership registration gives access to full resolution diagrams.

    Nokia 5110/PCD8544 Instruction Set

PCD8544 Initialisation

The datasheet in Section 8.1 advises that "attention should be paid to the possibility that the device may be damaged if not properly reset". It further then advises that the reset pulse (port B pin 1 in the following code) must be ‹0.3Vdd when Vdd reaches Vdd(min) or higher within a maximum time fo 100ms afater Vdd goes high. This means the function Nokia_Init() should be called early within the PIC code execution. Figure 16 shows the timing diagram for the reset/initiation function, but the datasheet doesn't actually list the timing requirements for the minimum/maximum time that the reset pin needs to be held low. The codes uses a time of 10msec which worked consistently. The originator of the base code (2) advises that times less than 10msec also work, however, since start-up time is not particularly crucial to the applications in question, I haven't experimented with determining minimum workable timing. The most other relevent point from the data sheet in terms of initialisation is that the contents of all internal registers and RAM within the Nokia 5110/PDC8544 are undefined upon power-on. The remainder of the initialisation is to set the initial conditions for the internal registers (temperature coefficient, constrast level etc) and ensures that all pixels are off (all RAM locations set equal to zero).

PCD8544 Operation/Instructions

Using the PDC8544 requires sending the relevent instructions via the "bit-banging" interface. As previously noted, there are two types of instructions, firstly, those that change the operational status of the PDC8544 controller, and secondly "write data" instructions which load information to the PDC8544 display RAM (i.e. set LCD pixels on or off). Changing the operational status of the PDC8544 is further differentiated into two sub-categories. Firstly, when bit DB0 of the command byte is set high (i.e. H=1 within the datasheet). This enables changing the temperature coefficient (required when the LCD will be operated in cold temperatures, to enable the LCD crystals to remain responsive at lower temperatures), the bais system (datasheet recommends Mux 1:48 so left this as is, didn't appear to make much of a difference) and the LCD screen contrast (Vop). These "H=1" instructions are mostly set during initisation and not routinely changed during ongoing operation.

The second sub-category of "operational instruction" is when bit DB0 of the command byte is set low (i.e. H=0 within the datasheet). This enables selection of types of display control (normal, inverse video, blank screen etc) and setting the X and Y location of RAM address pointers (which enables changing of particular pixels on the LCD screen). The functions and various compiler "defines" within the code library enable selection of the these functions as required by using bitwise arithmetic (i.e. bitwise AND to create the necessary bit pattern for the "command byte" to be send to the PCD8544). The most important item to remember is that particular functions are only available if the DB0 bit has been previously set appropriately. The library routines for changing RAM address pointers and display control assume that DB0 of the command byte has been previously set/sent as low. Therefore, if for example the LCD contrast is changed during PIC program operation (other than at initialisation using the code as written), the DB0 bit must be set and reset as appropriate.

Power Supply

A typical "wall-wart" power-supply is used (a surplus laptop charger in this case) in conjunction with a voltage regulator (LM7805) to provide the regulated 5V required by the PIC microcontroller.

Note, the Nokia 5110 LCD requires a 3.3V supply (from the datasheet, 2.7-3.3V) which consumes ~7mA during normal operation. There are numerous ways this can be done, and in this case a LM1086 voltage regulator is used to step down the 5V from the LM7805.

Similarily, the Nokia 5110 LCD inputs require 3.3V (from the datasheet, all input voltages -0.5V to Vdd+0.5V), but the PIC16F876A microcontroller produces 5V output. Some references on the web advise they have successfully used 5V input from microcontroller into the Nokia 5110 LCD (but probably not advised - 'level shifting' components are cheaper than replacing a burnt-out 5110). The CD4050 non-inverting hex buffer provides a readily available, convenient solution (3.3V connected to pin 1) that acts as a 'level shifter'.

The only other item of note is that there are four white LED's spaced around the actual LCD of the Nokia 5110, and R2 in the schematic acts as the current limiting resistor for these 'backlight' LED's.

Circuit Operation

The schematic shows the basic minimum circuit to demonstrate the operation of the Nokia 5110 LCD, in this case, controlled/interfaced to a PIC16F876A microcontroller.

The LM7805 provides the 5V circuit voltage (stepping down from the 12V input from a "wall-wart" power-supply) with the LM1086 stepping down the 5V to 3.3V necessary for operation of the Nokia 5110.

The crystal X1 and associated capacitors C1 and C2 provide the oscillator for the PIC16F876A microcontroller. Incircuit serial programming (ICSP) of the PIC16F876A microcontroller is provided via connector J1 with switch SW1, resistor R1 and diode D2 providing voltage protecting during loading code into the PIC microcontroller.

Control signals from the PIC16F876A microcontroller are sent from port B (pins 22 to 26) via the CD4050 that converts the PIC 5V output to 3.3V suitable for input to the Nokia 5110 LCD.

Calibration

No calibration as such is required. However, the contrast value (see the experimental results section) is relatively sensitive, and if not set appropriately the screen will appear 'blank'. A contrast value of ~60 was best for the actual Nokia 5110 LCD's I was testing (a value <50 resulted in 'white-out' display, whereas, >75 gave a 'black-out').

Note: Image loading can be slow depending on server load.

  • Nokia 5110 Basic Interface SchematicNokia 5110 Basic Interface Schematic

    Silver Membership registration gives access to full resolution schematic diagrams.

    Nokia 5110 Basic Interface Schematic

This project did not require a PCB.

The construction was done using prototyping board. See the photographs and schematic diagram sections.

Qty Schematic Part-Reference Value Notes/Datasheet
Resistors
1R110k1/4W, 10% 
1R2100R1/4W, 10% 
Capacitors
2C1,C222pFCeramic 
1C30.33uF 
1C40.1uF 
Diodes
1D21N-4004 
Integrated Circuits
1U1PIC16F876APIC microcontroller datasheet
1U2LM7805Linear Voltage Regulator datasheet
1U3CD4050Hex non-Inverting Buffer datasheet
1U4LM1086IT 3.3Linear Voltage Regulator  datasheet
Miscellaneous
1J1CONN-H55-pin connector for ICSP
1Z1 Nokia 5110 LCD
1SW1SW-SPDT 
1X110MHzCrystal Oscillator

Description Downloads
Nokia 5110 LCD Bill of Materials Text File Download

The majority of the testing simply involves exploring/developing the PIC16F876A code library to provide the necessary interfacing and control.

The video below shows a demonstration of the Nokia 5110/PCD8544 LCD interfaced with PIC 16F876A. The demonstration code is discussed below (with download links provided in the table at the end of this section) which is based upon (3).

PIC Microcontroller Interface Code

The PIC micrcontroller code is based upon the Graphic LCD Nokia 3310 (LPH7779) routines by Michel Bavin (3). The code has been modified to work with the Nokia 5110, provides a couple of ancillary functions (e.g inverted video mode) and enables a larger font size/character set to be displayed. Various downloads are available in the table below.

The header file contains various #define's used to specify the Nokia 5110 command set, character font bit-pattern definitions and the following functions:


 void Nokia_Init(void);  
     // sets internal registers (temperature coefficient, constrast level  
     // etc) and ensures that all pixels are off (all RAM locations set                       
     // equal to zero). Nokia 5110 in 'basic instruction mode' after exit                       
 void Nokia_Clean_Ddram(void);                 
     //all pixels set to 0 - LCD is cleared 
 void Nokia_GotoXY(byte Nokia_X, byte Nokia_Y);
     // The Nokia 5110 upon receiving a data instruction, sets the received 
     // bits starting at the current X and Y location. The address pointers 
     // are then auto incremented depending if horizontal or vertical mode. 
     // The values of the X and Y address pointers cannot be read (only set).
 void Nokia_PrintChar(byte theChar);
     // The character is displayed at the current X and Y pos as set by the 
     // address pointers. Assumes a character font size of 5 x 8 bits.
 void Nokia_PrintCharROM(byte theChar);
     // Same as Nokia_PrintChar but utilise EEPROM to save ROM within the PIC.
 void Nokia_PrintBigFont(long theNumerial); 
     // Enables a 12 x 16 font size to be displayed. Due to amount ROM/RAM 
     // required, only the digits 0-9 and "." and "deg" sign are included.
 void Nokia_Write_Command(char Nokia_Command);
     // The command/function is performed. Valid bit patterns(Nokia_Command)
     // are formed by bitwise AND of the compiler #define constants.
 void Nokia_Write_Data(char Nokia_Data);
     // Display RAM is changed, the appropriate pixels on the LCD set/reset.
 void Nokia_Write_DorC(char Nokia_Data);
     // Performs either desired instruction or sets the display RAM pixels
     // on/off. Called from either Nokia_Write_Data or Nokia_Write_Command 
     // to ensure nok_dc has been set HIGH/LOW (data/command respectively).     
                

The Nokia 5110 should be initialised by calling Nokia_Init() as soon as possible after power-on. The following code snippet reproduces Nokia_Init() which shows the Nokia 5110 parameters initialised (contrast, temp coefficient, bias and video mode) and how Nokia_Write_Command() is used to alter the behaviour of the Nokia 5110.

 
 void Nokia_Init(void) {
   output_low(nok_sdin);
   output_low(nok_sclk);
   output_low(nok_dc);            
   output_low(nok_res);   // reset chip during 250ms
   delay_ms(2);           // worked without a delay (10Mhz Fosc), but left in 2ms "to be safe"
   output_high(nok_res);
   Nokia_Write_Command(PCD8544_FUNCTIONSET | PCD8544_CHIPACTIVE | PCD8544_HORIZ | PCD8544_EXTENDINSTSET);  
   Nokia_Write_Command(PCD8544_SETCONTRAST | 45); // Range: 0-127 (0x00-0x7F)
   Nokia_Write_Command(PCD8544_TEMPCONTROL | PCD8544_TEMPCOEFF0);  
   Nokia_Write_Command(PCD8544_SETBIAS | 0x04); //set bias, BS2,BS1,BS0 = 0b100 = 4, recommended by datasheet 1:48 mux
   Nokia_Write_Command(PCD8544_FUNCTIONSET | PCD8544_CHIPACTIVE | PCD8544_HORIZ | PCD8544_BASICINSTSET);
   Nokia_Write_Command(PCD8544_DISPCONTROL | PCD8544_NORMALMODE);
   Nokia_Clean_Ddram(); //set all pixels off to avoid random pixels 'on' at power-on/initiation
 }                
                

The following example program (output shown in the video above) demonstrates potential functionality including:

  • Displays "HELLO WORLD" with some of the text in inverse video mode
  • Use's a larger font (12 x 16)
  • Use of printf to control the formatting of output to LCD
  • Changes contrast setting to enable determine optimum for particular LCD
  • Demo's inverse video mode for whole LCD
 
#include "NokiaLCD_PIC16F876A.h"
#include "NokiaLCD.h"

void main() {   
   int i,toggle,contrast,contrastValue,theASCII;
   float fvalue;
   char LCDscroll[14]; 
   
   setup_adc_ports(NO_ANALOGS);
   setup_adc(ADC_OFF);
   setup_spi(FALSE);
   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DISABLED,0,1);
   setup_comparator(NC_NC_NC_NC);
   setup_vref(FALSE);

   nokia_init();      //required ASAP after power-on to initialise Nokia 5110
   Nokia_GotoXY(0,0); //ensure X and Y pointers set to 0,0
   Disp_Mode=0;
   printf(Nokia_PrintCharROM,"HELLO");
   Disp_Mode=1;
   printf(Nokia_PrintCharROM," WORLD ");
   Disp_Mode=0;
   printf(Nokia_PrintCharROM,":)");
   // print some "big font" numerals
   theASCII=52; //52dec=0x34="4"
   nokiaRow=1;  //need to have global variables to maintain current X and Y location of PDC8544
   nokiaCol=0;  //as the "big font" goes across "columns" and "rows" that otherwise fit the 
                //6x8 font to can use the PDC8544 internal X and Y pointers
   Nokia_GotoXY(nokiaCol,nokiaRow);
   for(i=0;i<=5;++i) { //"big font" only has the numerals and decimal character
       nokia_printBigFont(theASCII);
       theASCII++;
   }
   theASCII = 40; fvalue = 0; contrast=50; strcpy(LCDscroll,"             ");
   do {  
      Nokia_GotoXY(0,5);
      printf(Nokia_PrintCharROM,"%3.1g",fvalue);
      //show how can have "big font" displayed using printf etc
      nokiaRow=4; nokiaCol=29;
      Nokia_GotoXY(nokiaCol,nokiaRow); //need to set nokiaRow and nokiaCol as these are global's used by nokia_printBigFont internally
      fvalue = fvalue+0.1;
      printf(nokia_printBigFont,"%3.1g",fvalue);
      //scrolling banner of entire character set
      for (i=0;i<12;i++) {LCDscroll[i]=LCDscroll[i+1];}
      LCDscroll[12]=theASCII;
      Nokia_GotoXY(0,3);
      printf(Nokia_PrintChar,LCDscroll);
      theASCII++;
      // this is to demonstrate inverse video mode
      if (theASCII>90) { //126) { 
         theASCII = 40; //theASCII=32;
         if(toggle) {
            nokia_write_Command(PCD8544_DISPCONTROL | PCD8544_INVERSEMODE);
            toggle=FALSE;
         } else {
            nokia_write_Command(PCD8544_DISPCONTROL | PCD8544_NORMALMODE);
            toggle=TRUE;
         }         
      }
      Nokia_GotoXY(0,4); //next section is to change contrast value to show effect on LCD
      contrast++;
      if (contrast>64) contrast=30;
      contrastValue=(contrast/5)*5;
      printf(Nokia_PrintCharROM,"ct=%2u",contrastValue); 
      nokia_write_command(PCD8544_FUNCTIONSET | PCD8544_CHIPACTIVE | PCD8544_HORIZ | PCD8544_EXTENDINSTSET);
      nokia_write_command(PCD8544_SETCONTRAST | contrastValue);
      nokia_write_command(PCD8544_FUNCTIONSET | PCD8544_CHIPACTIVE | PCD8544_HORIZ | PCD8544_BASICINSTSET);    
      delay_ms(250); //give a delay so can see what is happening on the LCD
   } while (TRUE);
}                
                

PIC Microcontroller Code Downloads

Description Downloads
Nokia 5110 LCD header file (with 'big font'): CCS C Source Code Download
Example code with PIC16F876A/Nokia 5110 (as demonstrated in video above): CCS C Source Code Download
Hex Code Download
Microsoft Excel spreadsheet to design font characters for the Nokia 5110 LCD: Spreadsheet Download

Nokia 5110 LCD Font Code/Design

The Nokia 5110 LCD does not a 'font' or 'characters' automatically available (unlike for example a dot-matrix HD44780 LCD that is commonly used with DIY microcontroller projects). The Nokia 5110 display RAM consists of 84 by 48 bits (X versus Y address), but the Y address is in the form of one byte at a time. This means individual bits within the Y address cannot be accessed independently. This effectively then gives 84 columns (0 to 83 "X addresses") and 6 rows (0 to 5 "Y addresses").

Therefore, a font bit pattern is constructed from a series of byte values which represent a 'column' pixel pattern (top to bottom), and each sucessive byte value building up the displayed character (left to right) - using the horizontal addressing mode. See the Background Section for some more detail and a diagram of this process.

Since the Y address is a group of 8-bits, the most 'natural' font is 8-bits high, which with 5-bits wide gives a aesthetically pleasing result. A full character set of 8x5 bit font is provided in the PIC Microcontroller header code file. While the 8x5 font provides legible characters on the Nokia 5110 screen (effectively 16 characters wide by 6 characters high), a larger font is useful in many applications (e.g. display of time, date etc).

With this in mind, a font that consists of 2 bytes high by 12 bytes wide was designed for the "numeral" characters (termed the 'bigFont' in the associated PIC Microcontroller code). A Microsoft Excel spreadsheet is available that enables visual design of bit-patterns for font characters, which then calculates the byte values necessary to create the font in the microcontroller code (see the downloads table above).

The construction was done using prototyping board. See the photographs and schematic diagram sections.

Important to note that the Nokia 5110 operates at a nominal 3.3V, and since PIC micrcontrollers (and similar) typically operate at 5V, will likely need seperate voltage regulator and level shifting (see Circuit Details section).

Also important to note that a current limiting resistor is required for the 'back light' LEDS (pin 7 on the version of the Nokia 5110 tested) - R2 in the circuit diagram.

The contrast value (see the Testing/Experimental Results Section) is relatively sensitive, and if not set appropriately the screen will appear 'blank'. This is a kind of 'gotcha' when tying to initially test if code/connections are correct (i.e. don't just display 'hello world' or similar, but set contrast level as well). A contrast value of ~60 was best for the actual Nokia 5110 LCD's I was testing (a value <50 resulted in 'white-out' display, whereas, >75 gave a 'black-out').

Comments/Questions (2)

Topic: Nokia 5110 LCD
Sort
ohyeahFTW says...
where did you buy the 5110 screens you did the testing with
7th June 2015 3:10pm
FadsToObsessions says...
purchased them just from ebay/Hong Kong supplier (do a search on ebay for 'Nokia 5110'), from memory got a pack of 5 for about $15. I can PM you the actual supplier I used if you like (seem reliable, they are cheap but items takes a while to arrive via the post).
7th June 2015 3:29pm
Page 1 of 1

Add Comment/Question

Only Logged-In Members can add comments

"If we could sell our experiences for what they cost us, we'd all be millionaires".

Please donate any amount to help with hosting this web site.

If you subscribe (only $2/annum) you can view the site without advertisements and get emails abouts updates etc.

X

Sorry!

Only logged-in users with correct Membership Level can download.


Membership starts at only $2, so join now!