Interfacing LCD with 8051 (8-Bit)


An LCD is an Liquid Crystal Display which displays electronic visual display. For more information about the controller, click on this Tutorial on LCD 


lcd pin outs

Connections to the 8051:

We need to connect our LCD pinouts to a port of the 8051 microcontroller and program the controller to display characters on the LCD. More information in the Tutorial on LCDLCD with 8051


Steps for the LCD to work: 

RS- Register Select:
There are 2 very important registers in LCD; the Command Code register and the Data Register. 

If RS=0, the Code register is selected, allowing user to send command
If RS=1, the Data register is selected allowing to send data that has to be displayed.

R\W- Read\Write:
R\W input allows the user to write information to LCD or read information from it. How do we read data from LCD? The data that is being currently displayed will be stored in a buffer memory DDRAM. This data could be read if necessary.

If R\W=1, then set for reading Reading
R\W=0, then set for reading Writing

E- Enable:
The enable Pin is used by the LCD to latch information at its data pins. When data is supplied to data pins, a high to low pulse must be applied to this pin in order for the LCD to latch the data present in the data pins.

E=1 then 0, set the LCD a Toggle

General Explanation:
We have to prepare an LCD properly before the character we need, has to be displayed. For this a number of commands have to be provided to the LCD before inputting the required data. The commands will be discussed in the later part of this tutorial.

LCD doesn’t know about the content (data or commands) supplied to its data bus. It is the user who has to specify whether the content at its data pins are data or commands. For this, if a command is inputted then a particular combination of 0s and 1s has to be applied to the control lines so as to specify it is a Command on the other hand if a data is inputted at the data lines then an another combination of 0s and 1s has to be applied to the control lines to specify it is Data.

If we need to send a command to the lcd then set RS=0, R\W=0, E=1\0
If we need to send a Data to the lcd then set RS=1, R\W=0, E=1\0

More information in the Tutorial on LCD

The following are the different types of command instructions:

LCD commands


Programming the 8051 in 'C': 

The Port data of the lcd (D0-D7) is set to Port 3 and the flowing connection RS=P2.0, RW=P2.1, E=P2.2 

/*calls a time delay before sending next data/command
P3.0-P3.7 are connected to LCD data pins D0-D7
P2.0 is connected to RS pin of LCD
P2.1 is connected to R/W pin of LCD
P2.2 is connected to E pin of LCD   */

#include < reg51.h >

void datasend (unsigned int i);
void commandsend(unsigned int i);
void delay(int j);

void main(void)
unsigned char i =0;
char name[] = "Ste";

   //swend the begining commads - Always
   commandsend(0x38);   //init. LCD 2 lines,5x7 matrix
   commandsend(0x0e); //display on, cursor on
   commandsend(0x01); //clear lcd
   commandsend(0xc0); //cursor
//send the data on the first line
commandsend(0x80); //sets line on the first line
for(i =0; i<3; i++)

commandsend(0xC0); //sets line on the first line
   //second line  send data
for(i =0; i<3; i++)

while(1); //infinite loop

void commandsend(unsigned int i) //sending commands to lcd
{  P3 = i  ;
 P2 = 0X04;  //rs = 0, rw = 0, e = 1
 P2 = 0X00;   //clear enable to make pulse

void datasend (unsigned int i) // sending data to lcd
{  P3 = i ;
 P2 = 0X05; //rs = 1, rw = 0, e = 1
 P2 = 0X01; //clear enable to make pulse
void delay(unsigned char i)
unsigned int rr;
   for (rr = 0; rr < i; rr++);

Download Project Folder

Project includes the projects in C compiled from Keil UV4 and the Proteus schematic.

electronics control,
Aug 13, 2011, 5:45 AM
electronics control,
Aug 13, 2011, 5:45 AM