Engineers Garage

  • Electronic Projects & Tutorials
    • Electronic Projects
      • Arduino Projects
      • AVR
      • Raspberry pi
      • ESP8266
      • BeagleBone
      • 8051 Microcontroller
      • ARM
      • PIC Microcontroller
      • STM32
    • Tutorials
      • Audio Electronics
      • Battery Management
      • Brainwave
      • Electric Vehicles
      • EMI/EMC/RFI
      • Hardware Filters
      • IoT tutorials
      • Power Tutorials
      • Python
      • Sensors
      • USB
      • VHDL
    • Circuit Design
    • Project Videos
    • Components
  • Articles
    • Tech Articles
    • Insight
    • Invention Stories
    • How to
    • What Is
  • News
    • Electronic Product News
    • Business News
    • Company/Start-up News
    • DIY Reviews
    • Guest Post
  • Forums
    • EDABoard.com
    • Electro-Tech-Online
    • EG Forum Archive
  • DigiKey Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Learn
    • eBooks/Tech Tips
    • Design Guides
    • Learning Center
    • Tech Toolboxes
    • Webinars & Digital Events
  • Resources
    • Digital Issues
    • EE Training Days
    • LEAP Awards
    • Podcasts
    • Webinars / Digital Events
    • White Papers
    • Engineering Diversity & Inclusion
    • DesignFast
  • Guest Post Guidelines
  • Advertise
  • Subscribe

How to interface Graphics LCD with 8051 Microcontroller (AT89C52)- (Part 43/45)

By Himanshu Choudhary March 29, 2011

 
User friendly visual displays are used nowadays to keep track of working of any device. Such a visual display can be anything ranging from old Analog meters to new and smart Digital meters. In digital world to keep track of devices, LCDs are very commonly used. LCDs are easy to program and prove to be a better display unit as compared to other devices like seven segments and LED display units.
 
The graphics LCDs are preferred over the character LCDs for those applications where both character and graphical representation are required. This article explains the basics of a 128x64 Graphics LCD and how it can be interfaced with AT89C52 to display basic shapes.

 

 


To interface this LCD with microcontroller, two registers (Input and Output register) are provided in the LCD. These registers are selected by the combination of RS and RW signals. These combinations are given in the following Table1.
 
Input Register:
Input Register is used while giving instructions and writing data to LCD. It holds the data/instruction temporarily before writing to DDRAM (Data Display RAM). When the LCD is in active mode (CS1 and CS2 high), the Input register can be selected by sending bits on RS and RW pins as shown in the following table. The data of input register is latched in at the falling edge (from high to low) of EN (Enable) signal and written into DDRAM automatically through internal operation.
 
Output Register:
Output Register is used to read data from DDRAM and to check status data (busy check). When the LCD is in active mode (CS1 and CS2 high), the Output register can be selected by sending bits on RS and RW pins as shown in the following table. When R/W and RS are high, data is latched into output register and when R/W=H, RS=L, status data (busy check) can be read out.
 
R/W
RS
Function
L
L
Send Instruction
H
Data Write (From Input Register to DDRAM)
H
L
Status Check (Busy Read)
H
Data Read (From DDRAM to Output Register)
Fig. 2: RS and RW Combination for selection of register
 
The basic operation with graphical LCD requires following steps:
1.      LCD Initialization
2.      Page Selection
3.      Column Selection
4.      Data Display
 
All these steps have been explained in the following sections with corresponding instruction sets.
 
1.    LCD Initialization
Before displaying anything on graphics LCD, it must be initialized, i.e., display must be put on and column/page selection be made. This is achieved by giving proper instructions to the LCD. To make Display OnOff the following set of instructions must be followed in order:
 
a)    Put these values in Data Register
 
DB7
DB6
DB5
DB4
DB3
DB2
DB1
DB0
0
0
1
1
1
1
1
D
 Fig. 3: Bit Values in Data Register for LCD Initialization
 
Data appears when D=1 and disappears when D=0.  When the display is off, there is no effect on the data which is stored in DDRAM.
b)   CS1=1,CS2=1(to activate display of both halves of LCD)
c)    RS=0, R/W=0 (to select the instruction mode)
d)   EN=1
e)    Delay
f)    EN=0 (to latch data into the input register)
Display on/off function can also be used to blink data continuously on the LCD by switching the display with some delay.
 
2.    Page selection
Before writing any data, the page of LCD must be selected. Page can be selected through following steps:
 
a)    Put these values in Data Register
 
DB7
DB6
DB5
DB4
DB3
DB2
DB1
DB0
1
0
1
1
1
X3
X2
X1
 Fig. 4: Bit Values in Data Register for Page Selection
 
Since there are a total of 8 pages (0–7), a particular page is selected by setting three bits (X1-X3).
b)   CS1=1, CS2=1(to activate display of both halves of LCD)
c)    RS=0, R/W=0 (to select the instruction mode)
d)   EN=1 
e)    Delay
f)    EN=0 (to latch data into the input register)
For example, if X3=0, X2=1 and X1=0, then the second page is selected. Reading or writing operation is done on this page until next page is set. Depending on the column selection, the page is selected from either left or right half of the graphics LCD.
 
3.    Column selection
There are 128 [64 (=26) columns per half] in graphics LCD and they are automatically incremented. This means that after selecting a column, it increases on its own by one, after each write cycle. So it is easier to write data column by column. A column can be chosen through following instructions:
 
a)    Put these values in Data Register
 
DB7
DB6
DB5
DB4
DB3
DB2
DB1
DB0
0
1
Y5
Y4
Y3
Y2
Y1
Y0
 Fig. 5: Bit Values in Data Register for Column Selection
 
 
 The corresponding controller (CS1 or CS2) is selected depending on the Column number as shown below.
 
Column Value For Controller Selection
Fig. 6: Column value for Controller Selection
 
b)   RS=0, R/W=0 (to select the instruction mode)
c)    EN=1
d)   Delay
e)    EN=0 (to latch data into the input register)
For example, if Page address is 0 and Column address is 0, then 0th column of page 0 is selected, i.e., the first pixel will be selected which is highlighted in the following diagram.
 
Bitmap Values On LCD
 
 Fig. 7: Bitmap Values On Lcd
 
4.    Display data
After page and column selection, data can be sent to LCD for display. The programming steps for display data are as given below:
 
a)         Put the data values in Data Register. With every write cycle, data is written in one column and the column then gets auto-incremented. A high data bit (DBx = 1) corresponds to activated (dark) pixel and low data bit (DBx = 0) corresponds to deactivated (light) pixel. Here MSB corresponds to 8th row in column and LSB to 1st row of column.
b)        If column<63 then (CS1=1 & CS2=0) else (CS1=0 & CS2=1)
c)        RS=1 and R/W=0 (to select write mode of LCD)
d)       EN=1
e)        Delay
f)         EN=0 (to latch data into the input register)
 
If data port is given value ‘0x99’ or ‘10011001’ then column takes the values as shown below.
 
 
The following points can be included in above programming steps for efficient programming:
1.        While sending data to be written with array, one can specify the array limit as well. This limit signifies the number of columns one wants to write at once. If the limit is 8, eight columns will be written at once and if it is 7, seven columns will be written in one go.
2.        The condition ‘if (column >127)’ can be used to return the control back to the main function if the limit exceeds the number of columns present in the LCD.
3.        The function for setting column should be called again if array limit condition doesn’t fit in left page and has to be extended to right page too.
4.        Though column address increases itself by one but one variable should be taken to check the conditions (ii) & (iii) explained above.
 
To use above functions, a simple experiment can be done to display alphabetic characters in different fonts. Here, the alphabet ‘A’ is being displayed in different fonts.
 
These shapes can be displayed by using their corresponding bitmap values shown in the above diagram. The connection of graphical LCD with AT89C52 is shown in circuit diagram. Also learn to display text/string and display image on Graphics LCD.

 

Project Source Code

###

/*Program to display simple text on Graphics LCD*/

#include<reg51.h>
#include<intrins.h>
#define dport P2

sbit rs=P1^0;
sbit rw=P1^1;
sbit en=P1^2;
sbit cs1=P1^3;
sbit cs2=P1^4;

unsigned char c,z=0;
unsigned char ar0[]={124,126,19,19,126,124,0,0};    //A,8x8
unsigned char ar1[]={65,127,127,73,127,54,0,0};	    //B,8x8
unsigned char ar2[]={28,62,99,65,65,99,34,0};	    //C,8x8
unsigned char ar3[]={65,127,127,65,99,62,28,0};     //D,8x8
unsigned char ar4[]={65,127,127,73,93,65,99,0,};    //E,8x8
unsigned char ar5[]={ 65,127,127,73,29,1,3,0};      //F,8x8
unsigned char ar6[]={ 28,62,99,65,81,115,114,0};    //G,8x8
unsigned char ar7[]={127,127,8,8,127,127,0,0};      //H,8x8

unsigned char ar00[]={126,17,17,17,126}; 		//A,5x7
unsigned char ar11[]={127,73,73,73,54};		        //B,5x7
unsigned char ar22[]={62,65,65,65,34};			//C,5x7
unsigned char ar33[]={127,65,65,34,28};			//D,5x7
unsigned char ar44[]={127,73,73,73,65};			//E,5x7
unsigned char ar55[]={127,9,9,1,1};			//F,5x7
unsigned char ar66[]={62,65,65,81,50};			//G,5x7
unsigned char ar77[]={127,8,8,8,127};			//H,5x7
		  
void ctrloff()
{
	rs=0;
	rw=0;
	en=0;
	cs1=0;
	cs2=0;
}

//Display on function			 
void displayon()
{ 
	ctrloff();
	dport=0x3f;  
	cs1=1;cs2=1;
	rw=0;rs=0;
	en=1;
	_nop_(); 
	en=0;
}

void setcolumn(unsigned char y)
{
	if(y<64)
	{
		ctrloff();
		c=y;
		dport=0x40|(y&63);	  //0x40 represents Column 0
		cs1=1;cs2=0;
		rs=0;
		rw=0;
		en=1;
		_nop_(); 
		en=0;
	}
	else
	{ 
		c=y;
		dport=0x40|((y-64)&63);	  //0x40 represents Column 0
		cs2=1;cs1=0;
		rs=0;
		rw=0;
		en=1;
		_nop_(); 
		en=0;
	}
}

void setpage(unsigned char x)
{
	ctrloff();
	dport= 0xb8|x;	   //0xb8 represents Page 0
	cs1=1;
	cs2=1;
	rs=0;
	rw=0;
	en=1;
	_nop_(); 
	en=0;
}

void lcddata(unsigned char *value,unsigned int limit)
{
	unsigned int i;
	for(i=0;i<limit;i++)
	{
		if(c<64)
		{
			dport=value[i];
			cs1=1;cs2=0;
			rs=1;
			rw=0;
			en=1;
			_nop_(); 
			en=0;
			c++;
		}

		else
		{
			setcolumn(c); 
			dport=value[i];
			cs2=1;cs1=0;
			rs=1;
			rw=0;
			en=1;
			_nop_(); 
			en=0;
			c++;
		}
	if(c>127)
	return;
	}
}

void clrlcd()
{
    unsigned char i,j;
    for (i=0;i < 8;i++)
    {
	setpage(i);
	setcolumn(0);
	for (j= 0 ;j < 128; j++)
           lcddata(&z,1);
    }
}

void main()
{ 
	clrlcd();
	while(1)
	{
		displayon(); 
		setpage(0);
		setcolumn(0);
		lcddata(&ar0,8);

		setpage(1);
		setcolumn(0);
		lcddata(&ar1,8);
	
		setpage(2);
		setcolumn(0);
		lcddata(&ar2,8);

		setpage(3);
		setcolumn(0);
		lcddata(&ar3,8);

		setpage(4);
		setcolumn(0);
		lcddata(&ar4,8);

		setpage(5);
		setcolumn(0);
		lcddata(&ar5,8);

		setpage(6);
		setcolumn(0);
		lcddata(&ar6,8);

		setpage(7);
		setcolumn(0);
		lcddata(&ar7,8);
 
		setpage(0);
		setcolumn(64);
		lcddata(&ar00,5);

		setpage(1);
		setcolumn(64);
		lcddata(&ar11,5);

		setpage(2);
		setcolumn(64);
		lcddata(&ar22,5); 

		setpage(3);
		setcolumn(64);
		lcddata(&ar33,5);

		setpage(4);
		setcolumn(64);
		lcddata(&ar44,5);

		setpage(5);
		setcolumn(64);
		lcddata(&ar55,5);

		setpage(6);
		setcolumn(64);
		lcddata(&ar66,5);

		setpage(7);
		setcolumn(64);
		lcddata(&ar77,5);

	} 
}

###

 


Circuit Diagrams

Circuit-Diagram-Interfacing-Graphical-LCD-8051-Microcontroller-AT89C52

Project Components

  • AT89C52 Microcontroller
  • Graphics LCD

Project Video


Filed Under: 8051 Microcontroller
Tagged With: 8051, graphics, lcd, microcontroller
 

Next Article

← Previous Article
Next Article →

Questions related to this article?
👉Ask and discuss on Electro-Tech-Online.com and EDAboard.com forums.



Tell Us What You Think!! Cancel reply

You must be logged in to post a comment.

EE TECH TOOLBOX

“ee
Tech Toolbox: 5G Technology
This Tech Toolbox covers the basics of 5G technology plus a story about how engineers designed and built a prototype DSL router mostly from old cellphone parts. Download this first 5G/wired/wireless communications Tech Toolbox to learn more!

EE Learning Center

EE Learning Center
“engineers
EXPAND YOUR KNOWLEDGE AND STAY CONNECTED
Get the latest info on technologies, tools and strategies for EE professionals.

HAVE A QUESTION?

Have a technical question about an article or other engineering questions? Check out our engineering forums EDABoard.com and Electro-Tech-Online.com where you can get those questions asked and answered by your peers!


RSS EDABOARD.com Discussions

  • Right Half Plane Zero
  • dc-dc converter in series
  • Single ended measuring ports and balanced antenna
  • Thermal modelling of repetitive power pulse
  • Permittivity and Permealibility in CST

RSS Electro-Tech-Online.com Discussions

  • Fun with AI and swordfish basic
  • Microinverters and storeage batteries?
  • FFC connector white
  • Is AI making embedded software developers more productive?
  • Can I make two inputs from one??

Featured – LoRa/LoRaWan Series

  • What is the LoRaWAN network and how does it work?
  • Understanding LoRa architecture: nodes, gateways, and servers
  • Revolutionizing RF: LoRa applications and advantages
  • How to build a LoRa gateway using Raspberry Pi
  • How LoRa enables long-range communication
  • How communication works between two LoRa end-node devices

Recent Articles

  • RPi Python Programming 21: The SIM900A AT commands
  • RPi Python Programming 22: Calls & SMS using a SIM900A GSM-GPRS modem
  • RPi Python Programming 23: Interfacing a NEO-6MV2 GPS module with Raspberry Pi
  • RPi Python Programming 24: I2C explained
  • RPi Python Programming 25 – Synchronous serial communication in Raspberry Pi using I2C protocol

EE ENGINEERING TRAINING DAYS

engineering

Submit a Guest Post

submit a guest post
Engineers Garage
  • Analog IC TIps
  • Connector Tips
  • Battery Power Tips
  • DesignFast
  • EDABoard Forums
  • EE World Online
  • Electro-Tech-Online Forums
  • EV Engineering
  • Microcontroller Tips
  • Power Electronic Tips
  • Sensor Tips
  • Test and Measurement Tips
  • 5G Technology World
  • Subscribe to our newsletter
  • About Us
  • Contact Us
  • Advertise

Copyright © 2025 WTWH Media LLC. All Rights Reserved. The material on this site may not be reproduced, distributed, transmitted, cached or otherwise used, except with the prior written permission of WTWH Media
Privacy Policy

Search Engineers Garage

  • Electronic Projects & Tutorials
    • Electronic Projects
      • Arduino Projects
      • AVR
      • Raspberry pi
      • ESP8266
      • BeagleBone
      • 8051 Microcontroller
      • ARM
      • PIC Microcontroller
      • STM32
    • Tutorials
      • Audio Electronics
      • Battery Management
      • Brainwave
      • Electric Vehicles
      • EMI/EMC/RFI
      • Hardware Filters
      • IoT tutorials
      • Power Tutorials
      • Python
      • Sensors
      • USB
      • VHDL
    • Circuit Design
    • Project Videos
    • Components
  • Articles
    • Tech Articles
    • Insight
    • Invention Stories
    • How to
    • What Is
  • News
    • Electronic Product News
    • Business News
    • Company/Start-up News
    • DIY Reviews
    • Guest Post
  • Forums
    • EDABoard.com
    • Electro-Tech-Online
    • EG Forum Archive
  • DigiKey Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Learn
    • eBooks/Tech Tips
    • Design Guides
    • Learning Center
    • Tech Toolboxes
    • Webinars & Digital Events
  • Resources
    • Digital Issues
    • EE Training Days
    • LEAP Awards
    • Podcasts
    • Webinars / Digital Events
    • White Papers
    • Engineering Diversity & Inclusion
    • DesignFast
  • Guest Post Guidelines
  • Advertise
  • Subscribe