Saturday, May 15, 2021

PIC18F2550 interfacing with Nokia 5110 LCD

Nokia 5110 LCD module is a popular graphical LCD module for electronics hobbyists. It has a built-in LCD controller, PCD8544 48x84 pixels matrix LCD controller/driver. There are some popular modules of this graphical LCD such as, SparkFun, and Adafruit. 

PIC18F2550 interfacing with Nokia 5110 LCD
A sample of prototyping

Serial Peripheral Interface (SPI) is communication interface between a microprocessor and this module. It is a high speed communication protocol. In this LCD module, there are only five wires relates to SPI, and other three wires for power and LED.

A popular one's from SparkFun

Hence there are 8 pins to connect to this module:

  1. VCC - Positive supply voltage (from 2.7 V to 3.3 V)
  2. GND - Ground connection
  3. SCE - Chip Select (active low)
  4. RST - Reset (active low)
  5. D/C - Data/Command mode ( low for command and high for data)
  6. DIN - SPI MOSI
  7. SCLK - SPI serial clock
  8. LED - LED backlight supplies at 3.3V maximum voltage

I will not list all its technical detail of programming here due to repetition with previous post. For programming detail, please see this post which shows the ATMega32 SPI interface to this LCD. This post show how to interface this LCD with PIC16F876A using MPLABX XC8 compiler. However it work only in software simulator without physical hardware testing.

In this post, I use my own prototyping board for PIC18F2550 to test this LCD module that I have not physically tested it before. I don't use internal SPI peripheral of PIC18F2550. The XC8 program will bit-bang the SPI via software. However using this method it will not create a high speed communication.

PIC18F2550 interfacing with Nokia 5110 LCD
Program testing on physical prototyping

Actual schematic is shown below.

PIC18F2550 interfacing with Nokia 5110 LCD
Schematic and program simulation

I use Proteus VSM 8 to draw its schematic, and also allow the simulation of program. Supply voltage for PIC18F2550 is +5V regulated DC voltage. Pin 20 and 8 of PIC18F2550 are VDD and GND for supply voltage. They are not shown in this schematic. In physical prototyping they must be properly wired to power bus.

Nokia 5110 LCD module interface with PIC18F2550 using +5V TTL logic level. However it requires a +3.3V regulated DC voltage to work properly. As it's shown in the schematic above, VCC and LED pin of LCD module connects to +3.3V power pin. This voltage source regulated by 78L33 +3.3V linear voltage regulator IC in TO-92 package.

PIC18F2550 interfacing with Nokia 5110 LCD
78L33 +3.3V voltage regulator in TO-92 package

This chip is able to source up to 100mA output, suitable to drive this small LCD module. External crystal oscillator for PIC18F2550 is 20MHz in frequency without using Phase Lock Loop (PLL) of the controller.

Source code for this example program is written using XC8 v1.35 with MPLABX v1.51, which are the earlier versions for both compiler and IDE.

/*
 * PIC18F2550 interfaces to Nokia 5110
 * SPI LCD using xc8
 */

#include <xc.h>
#include "pic18f2550Config.h"
#include "fonts.h"

#define _XTAL_FREQ 20000000

#define CS      LB0
#define RST     LB1
#define D_C     LB2
#define SDO     LB3
#define SCK     LB4

#define LCD_C     0
#define LCD_D     1

#define LCD_X     84
#define LCD_Y     48

unsigned char xCount=0;

void LcdCharacter( char charactor);
void LcdClear(void);
void LcdInitialize(void);
void LcdString( char *charactor);
void LcdWrite( char dc,unsigned char _data);
void SerialOut(unsigned char dat);
void lcdNewLine();

void main() {
    LcdInitialize();
    LcdClear();
    LcdString("akiTechnical");
    LcdString("Nokia5110 LCD");
    lcdNewLine();
    LcdString("interfaces");
    lcdNewLine();
    LcdString("with PIC18F2550");


    while(1){
    }
}

void LcdCharacter( char character){
     int i;
     static int xT=0;
     LcdWrite(LCD_D,0x00);
     for(i=0;i<5;i++){
         LcdWrite(LCD_D,ASCII[character-0x20][i]);
     }
     LcdWrite(LCD_D,0x00);
     xT+=1;
     if(xT>=12){
         xT=0;
     }
     xCount=xT;
}

void LcdClear(void){
     int i;
     for(i=0;i<LCD_X*LCD_Y/8;i++) LcdWrite(LCD_D,0x00);
}

void lcdNewLine(){
    int temp;
    temp=12-xCount;
    if(temp!=0){
     for(int i=0;i<temp;i++)
         LcdCharacter(' ');
    }
}

void LcdInitialize(void){
     TRISB=0x00;
     CS=1;
     RST=0;
     RST=1;

     LcdWrite(LCD_C,0x21); // LCD Extended Commands
     LcdWrite(LCD_C,0xB1); // SET LCD CONTRAST
     LcdWrite(LCD_C,0x04); // set temp coefficient 0x04
     LcdWrite(LCD_C,0x14); // LCD bias
     LcdWrite(LCD_C,0x20);
     LcdWrite(LCD_C,0x0C); // LCD normal Mode
}

void LcdString( char *character){
     while(*character) LcdCharacter(*character++);
}

void LcdWrite( char _dc, char _data){
     D_C=_dc;
     CS=0;
     SerialOut(_data);
     CS=1;
}

void SerialOut(unsigned char dat){
    unsigned char temp;
    for(int i=0;i<8;i++){
        temp=dat;
        SCK=0;
        // TESTING MSB IF 0 SHIFT 0 OTHERWISE 1
        ((temp&0x80)==0x00)?SDO=0:SDO=1;
        SCK=1;
        dat<<=1;
    }
}

Header files for device configuration, and font file are placed in the project folder. I will not show them here. Click here to download this example program.

No comments:

Post a Comment

Search This Blog

Labels

25AA010A (1) 8051 (7) 93AA46B (1) ADC (30) Analog Comparator (1) Arduino (15) ARM (6) AT89C52 (7) ATMega32 (54) AVR (57) CCS PICC (28) DAC (1) DHT11 (2) Display (105) Distance Sensor (3) DS18B20 (3) dsPIC (2) dsPIC30F1010 (2) EEPROM (5) Environment Sensor (4) esp8266 (1) I2C (29) Input/Output (67) Interrupt (19) Keil (5) Keypad (10) LCD (46) Master/Slave (1) MAX7221 (1) MCP23017 (5) MCP23S17 (4) Meter (3) MikroC (2) Motor (15) MPLABX (66) Nokia 5110 LCD (3) OLED (2) One-Wire (6) Oscillator (8) PCB (6) PCD8544 (3) PCF8574 (5) PIC (107) PIC12F (2) PIC16F628A (2) PIC16F630 (1) PIC16F716 (3) PIC16F818 (10) PIC16F818/819 (2) PIC16F84A (15) PIC16F876A (1) PIC16F877A (9) PIC16F88 (1) PIC16F887 (60) PIC18 (19) PIC18F1220 (4) PIC18F2550 (3) PIC18F4550 (12) PWM (11) RTC (8) Sensor (10) SH1106 (1) Shift Register (11) Shift Registers (2) SPI (24) STM32 (6) STM32 Blue Pill (6) STM32CubeIDE (6) STM32F103C8T6 (6) SysTick (3) temperature sensor (11) Thermometer (21) Timer/Counter (30) TM1637 (2) UART (7) Ultrasonic (4) Voltmeter (7) WDT (1) XC16 (2) XC8 (94)