In this project, we will interface a Graphical LCD (GLCD ) withan 8051 microcontroller. Nokia 5110 is a 48 x 84 graphic LCD that has an internal controller PCD8544 to control all displays and operations. The Nokia 5110 is interfaced to the microcontroller through a serial bus interface. After going through the project you can display the graphics or text you wish to be displayed. So let us begin our tutorial and learn how to interface a graphical LCD like Nokia 5110 Display to the 8051 microcontrollers.
let us first see the specifications:
8051 Microcontroller- 4KB bytes on-chip program memory (ROM)
- 128 bytes on-chip data memory (RAM)
- Four register banks
- 128 user-defined software flags
- 8-bit bidirectional data bus
- A 16-bit unidirectional address bus
- 32 general-purpose registers each of 8-bit
- 16-bit Timers (usually 2, but may have more or less)
- Three internal and two external Interrupts
- Four 8-bit ports, (short model have two 8-bit ports)
- 16-bit program counter and data pointer
- 8051 may also have a number of special features such as UARTs, ADC, Op-amp, etc.
- 48 x 84 Graphic LCD Display
- Serial Bus Interface
- Internal Controller – PCD8544
- LED Back-Light
- Supply Voltage 2.7 -5.0 Volt
- Low power consumption
- GND => Ground Pin | Connect to 8051 GND
- BL/LED => Pin to control LED (Back Light) | Connect to 3.3V
- VCC => Power Supply Pin from 7 – 5 V | Connect to 3.3V
- CLK => Pin Clock (Serial Clock Line for SPI communication) | Connect to P2^1 of 8051.
- DIN => Pin Data (Serial Data Line for SPI communication) | Connect to P2^2 of 8051.
- DC => Pin to select Command or Data mode for data formats | Connect to P2^3 of 8051.
- CE/SCE => Chip enable input. The enable pin allows data to be clocked in. The signal is active LOW. | Connect to P2^4 of 8051.
- RST => External reset. This signal will reset the device and must be applied to properly initialize the chip. The signal is active LOW. | Connect to P2^5 of 8051.
At the beginning of the program, a header file named “reg52.h” is included. It is a header file for generic 80C52 and 80C32 microcontroller. You can replace it with the header file of your controller which comes under 8051 family. After that, you can see two large arrays named “Graphics” and “LookUpTable”. The first one is for displaying graphics. And the latter is for writing normal text. You can replace the first one with the array of your own logo. Array for your logo can be generated by simply uploading the logo image in the following link. https://www.riyas.org/2017/01/online-tool-to-convert-bitmap-to-hex-nokia-arduino.html
#include<reg52.h>
sbit CLK=P2^1;
sbit DIN=P2^2;
sbit DC=P2^3;
sbit CE=P2^4;
sbit RST=P2^5;
void Send(unsigned char);
void Data(unsigned char);
void Cmd(unsigned char);
void setPixel(unsigned char, unsigned char);
void setCursor(unsigned char, unsigned char);
void allClear(void);
void Initialize_LCD(void);
void charDisp(unsigned char);
void stringDisp(unsigned char*);
unsigned char code Graphics [] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0xf0, 0xf8, 0xfc, 0x3c, 0x1c, 0x3c, 0x7c, 0xf8, 0xf8, 0xf0, 0x00, 0x00, 0x00, 0x00, 0xc0, 0xf0, 0xf8, 0xf8, 0x7c, 0x3c, 0x1c, 0x3c, 0x7c, 0xf8, 0xf8, 0xe0, 0x80, 0x00, 0x00, 0x00, 0x00, 0xc0, 0xfc, 0xfc, 0xfc, 0x3c, 0x1c, 0x1c, 0x1c, 0x1c, 0x1c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x1c, 0x1c, 0x3c, 0xfc, 0xfc, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0xf1, 0xff, 0xff, 0x3f, 0x1f, 0x0e, 0x0e, 0x1f, 0xff, 0xff, 0xfb, 0xf0, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x80, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x80, 0x8c, 0x8f, 0x8f, 0x0f, 0x0f, 0x07, 0x0f, 0xbf, 0xfe, 0xfe, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x07, 0x0f, 0x0f, 0x0e, 0x0e, 0x0e, 0x0f, 0x0f, 0x0f, 0x07, 0x03, 0x00, 0x00, 0x00, 0x01, 0x03, 0x07, 0x0f, 0x0f, 0x0e, 0x0e, 0x0e, 0x0f, 0x0f, 0x07, 0x03, 0x00, 0x00, 0x00, 0x01, 0x07, 0x0f, 0x0f, 0x0f, 0x0e, 0x0e, 0x0f, 0x0f, 0x0f, 0x07, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x0f, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0xf8, 0xf8, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xc0, 0xe0, 0xf0, 0xf0, 0x70, 0x78, 0x38, 0x38, 0x38, 0x78, 0x70, 0xf0, 0xf0, 0xe0, 0xe0, 0x40, 0x00, 0x00, 0x00, 0x00, 0xf8, 0xf8, 0xf8, 0x78, 0x38, 0x38, 0x78, 0x78, 0xf0, 0xf0, 0xf0, 0xe0, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0xff, 0xff, 0xff, 0x81, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xc7, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0x1f, 0x1f, 0x1f, 0x1c, 0x1c, 0x1c, 0x1c, 0x1c, 0x00, 0x00, 0x00, 0x00, 0x03, 0x07, 0x0f, 0x0f, 0x1f, 0x1e, 0x1c, 0x1c, 0x1c, 0x1c, 0x1c, 0x1e, 0x1e, 0x0f, 0x0f, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0x1f, 0x1f, 0x1c, 0x1c, 0x1c, 0x1c, 0x1c, 0x1e, 0x1f, 0x0f, 0x0f, 0x07, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
};
const unsigned char code LookUpTable [][5] =
{
{ 0x00, 0x00, 0x00, 0x00, 0x00 }, // space
{ 0x00, 0x00, 0x2f, 0x00, 0x00 }, // !
{ 0x00, 0x07, 0x00, 0x07, 0x00 }, // "
{ 0x14, 0x7f, 0x14, 0x7f, 0x14 }, // #
{ 0x24, 0x2a, 0x7f, 0x2a, 0x12 }, // $
{ 0xc4, 0xc8, 0x10, 0x26, 0x46 }, // %
{ 0x36, 0x49, 0x55, 0x22, 0x50 }, // &
{ 0x00, 0x05, 0x03, 0x00, 0x00 }, // '
{ 0x00, 0x1c, 0x22, 0x41, 0x00 }, // (
{ 0x00, 0x41, 0x22, 0x1c, 0x00 }, // )
{ 0x14, 0x08, 0x3E, 0x08, 0x14 }, // *
{ 0x08, 0x08, 0x3E, 0x08, 0x08 }, // +
{ 0x00, 0x00, 0x50, 0x30, 0x00 }, // ,
{ 0x10, 0x10, 0x10, 0x10, 0x10 }, // -
{ 0x00, 0x60, 0x60, 0x00, 0x00 }, // .
{ 0x20, 0x10, 0x08, 0x04, 0x02 }, // /
{ 0x3E, 0x51, 0x49, 0x45, 0x3E }, // 0
{ 0x00, 0x42, 0x7F, 0x40, 0x00 }, // 1
{ 0x42, 0x61, 0x51, 0x49, 0x46 }, // 2
{ 0x21, 0x41, 0x45, 0x4B, 0x31 }, // 3
{ 0x18, 0x14, 0x12, 0x7F, 0x10 }, // 4
{ 0x27, 0x45, 0x45, 0x45, 0x39 }, // 5
{ 0x3C, 0x4A, 0x49, 0x49, 0x30 }, // 6
{ 0x01, 0x71, 0x09, 0x05, 0x03 }, // 7
{ 0x36, 0x49, 0x49, 0x49, 0x36 }, // 8
{ 0x06, 0x49, 0x49, 0x29, 0x1E }, // 9
{ 0x00, 0x36, 0x36, 0x00, 0x00 }, // :
{ 0x00, 0x56, 0x36, 0x00, 0x00 }, // ;
{ 0x08, 0x14, 0x22, 0x41, 0x00 }, // <
{ 0x14, 0x14, 0x14, 0x14, 0x14 }, // =
{ 0x00, 0x41, 0x22, 0x14, 0x08 }, // >
{ 0x02, 0x01, 0x51, 0x09, 0x06 }, // ?
{ 0x32, 0x49, 0x59, 0x51, 0x3E }, // @
{ 0x7E, 0x11, 0x11, 0x11, 0x7E }, // A
{ 0x7F, 0x49, 0x49, 0x49, 0x36 }, // B
{ 0x3E, 0x41, 0x41, 0x41, 0x22 }, // C
{ 0x7F, 0x41, 0x41, 0x22, 0x1C }, // D
{ 0x7F, 0x49, 0x49, 0x49, 0x41 }, // E
{ 0x7F, 0x09, 0x09, 0x09, 0x01 }, // F
{ 0x3E, 0x41, 0x49, 0x49, 0x7A }, // G
{ 0x7F, 0x08, 0x08, 0x08, 0x7F }, // H
{ 0x00, 0x41, 0x7F, 0x41, 0x00 }, // I
{ 0x20, 0x40, 0x41, 0x3F, 0x01 }, // J
{ 0x7F, 0x08, 0x14, 0x22, 0x41 }, // K
{ 0x7F, 0x40, 0x40, 0x40, 0x40 }, // L
{ 0x7F, 0x02, 0x0C, 0x02, 0x7F }, // M
{ 0x7F, 0x04, 0x08, 0x10, 0x7F }, // N
{ 0x3E, 0x41, 0x41, 0x41, 0x3E }, // O
{ 0x7F, 0x09, 0x09, 0x09, 0x06 }, // P
{ 0x3E, 0x41, 0x51, 0x21, 0x5E }, // Q
{ 0x7F, 0x09, 0x19, 0x29, 0x46 }, // R
{ 0x46, 0x49, 0x49, 0x49, 0x31 }, // S
{ 0x01, 0x01, 0x7F, 0x01, 0x01 }, // T
{ 0x3F, 0x40, 0x40, 0x40, 0x3F }, // U
{ 0x1F, 0x20, 0x40, 0x20, 0x1F }, // V
{ 0x3F, 0x40, 0x38, 0x40, 0x3F }, // W
{ 0x63, 0x14, 0x08, 0x14, 0x63 }, // X
{ 0x07, 0x08, 0x70, 0x08, 0x07 }, // Y
{ 0x61, 0x51, 0x49, 0x45, 0x43 }, // Z
{ 0x00, 0x7F, 0x41, 0x41, 0x00 }, // [
{ 0x55, 0x2A, 0x55, 0x2A, 0x55 }, // 55
{ 0x00, 0x41, 0x41, 0x7F, 0x00 }, // ]
{ 0x04, 0x02, 0x01, 0x02, 0x04 }, // ^
{ 0x40, 0x40, 0x40, 0x40, 0x40 }, // _
{ 0x00, 0x01, 0x02, 0x04, 0x00 }, // '
{ 0x20, 0x54, 0x54, 0x54, 0x78 }, // a
{ 0x7F, 0x48, 0x44, 0x44, 0x38 }, // b
{ 0x38, 0x44, 0x44, 0x44, 0x20 }, // c
{ 0x38, 0x44, 0x44, 0x48, 0x7F }, // d
{ 0x38, 0x54, 0x54, 0x54, 0x18 }, // e
{ 0x08, 0x7E, 0x09, 0x01, 0x02 }, // f
{ 0x0C, 0x52, 0x52, 0x52, 0x3E }, // g
{ 0x7F, 0x08, 0x04, 0x04, 0x78 }, // h
{ 0x00, 0x44, 0x7D, 0x40, 0x00 }, // i
{ 0x20, 0x40, 0x44, 0x3D, 0x00 }, // j
{ 0x7F, 0x10, 0x28, 0x44, 0x00 }, // k
{ 0x00, 0x41, 0x7F, 0x40, 0x00 }, // l
{ 0x7C, 0x04, 0x18, 0x04, 0x78 }, // m
{ 0x7C, 0x08, 0x04, 0x04, 0x78 }, // n
{ 0x38, 0x44, 0x44, 0x44, 0x38 }, // o
{ 0x7C, 0x14, 0x14, 0x14, 0x08 }, // p
{ 0x08, 0x14, 0x14, 0x18, 0x7C }, // q
{ 0x7C, 0x08, 0x04, 0x04, 0x08 }, // r
{ 0x48, 0x54, 0x54, 0x54, 0x20 }, // s
{ 0x04, 0x3F, 0x44, 0x40, 0x20 }, // t
{ 0x3C, 0x40, 0x40, 0x20, 0x7C }, // u
{ 0x1C, 0x20, 0x40, 0x20, 0x1C }, // v
{ 0x3C, 0x40, 0x30, 0x40, 0x3C }, // w
{ 0x44, 0x28, 0x10, 0x28, 0x44 }, // x
{ 0x0C, 0x50, 0x50, 0x50, 0x3C }, // y
{ 0x44, 0x64, 0x54, 0x4C, 0x44 }, // z
{ 0x00, 0x08, 0x3e, 0x41, 0x00 } // {
};
void Send(unsigned char a){
unsigned char i;
for(i=0;i<8;i++){
CLK = 0;
if((a&0x80)){
DIN = 1;
} else {
DIN = 0;
}
CLK = 1;
a <<= 1;
}
}
void Data(unsigned char x){
DC = 1;
CE = 0;
Send(x);
CE = 1;
}
void Cmd(unsigned char x){
DC = 0;
CE = 0;
Send(x);
CE = 1;
}
/* Brings ram pointer to X,Y pixel position */
/* Input Arguments: x-> X cordinate range from 0 to 83 */
/* Input Arguments: y-> Y cordinate range from 0 to 5 */
void setPixel(unsigned char x, unsigned char y)
{
Cmd(0x40|(y&0x07)); // Y axis
Cmd(0x80|(x&0x7f)); // X axis
}
/* Clears the screen */
void allClear(void)
{
int pixel;
setPixel(0,0); // Cursor Home.
for (pixel=504;pixel>0;pixel--) {Data(0x00);} // 6*84 = 504 DDRAM addresses.
}
/* Nokia3310 LCD Initialization */
void Initialize_LCD(void)
{
RST = 1; // Set _RES HIGH.
CE = 1; // Disable Chip.
Cmd(0x21); // Activate Chip and H=1.
Cmd(0xb2); // Set LCD Voltage to about 7V.
Cmd(0x13); // Adjust voltage bias.
Cmd(0x20); // Horizontal addressing and H=0.
Cmd(0x09); // Activate all segments.
allClear(); // Erase all pixel on the DDRAM.
Cmd(0x08); // Blank the Display.
Cmd(0x0C); // Display Normal.
setPixel(0,0); // Cursor Home.
}
/* Bring cursor to Line and character specified */
/* Input Arguments: row -> Line number range from 1 to 6 */
/* Input Arguments: Column -> character position range from 1 to 14 */
/* You can have maximum of 6 lines of text on LCD and each line
containing 14 characters. Address is auto increment */
void setCursor(unsigned char row, unsigned char col){
if((row>6) || (row<1) || (col<1) || (col>14))
return;
setPixel(((col-1)*6),(row-1));
}
/* Writes single character on LCD */
/* Input Arguments: ch -> Character to be displayed */
void charDisp(unsigned char a){
unsigned char i, b;
if ( (a < 0x20) || (a > 0x7c) ){
a = 92;
}
for(i=0;i<5;i++){
b = LookUpTable[a - 32][i] << 1;
Data(b);
}
Data(0x00);
}
/* Writes character string on LCD */
/* Input Arguments: str -> Pointer to string to be displayed */
void stringDisp(unsigned char *p){
while(*p)
charDisp(*p++);
}
void Delay(int k)
{
int i,j;
for(i=0;i<k;i++)
for(j=0;j<1000;j++);
}
void main(){
int i;
Initialize_LCD();
//Bring Cursor to Line 1, character 1
setCursor(1,3);
//Print string to LCD
stringDisp("Aniket Arya");
Delay(1000);
setCursor(2,3);
stringDisp("8051 LCD");
Delay(1000);
//Bring pointer to 0,0 pixel position
setPixel(0,0);
//Write gfx data on LCD
for(i=0;i<504;i++)
Data(Graphics[i]);
while(1);
}
Simulation Results:You can find the Step by step tutorial in this video:
Comments