100% found this document useful (1 vote)
165 views

Interfacing A LCD Display With 8051

This document discusses interfacing an LCD display with an 8051 microcontroller to display characters. It describes how LCDs display characters based on the ASCII value of the data received. It then provides details on interfacing a 16x2 LCD with a P89V51RD2 8051 microcontroller, including the pin configurations and components required. The circuit diagram and program code to initialize the LCD and display messages are also included.

Uploaded by

bhaswati
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
165 views

Interfacing A LCD Display With 8051

This document discusses interfacing an LCD display with an 8051 microcontroller to display characters. It describes how LCDs display characters based on the ASCII value of the data received. It then provides details on interfacing a 16x2 LCD with a P89V51RD2 8051 microcontroller, including the pin configurations and components required. The circuit diagram and program code to initialize the LCD and display messages are also included.

Uploaded by

bhaswati
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

Interfacing a LCD display with 8051 microcontroller and displaying a

character on LCD
LCD is a very commonly used output device to display alphanumeric characters. The LCD
displays the character corresponding to the data received on its input data port i.e., it treats
the data as the ASCII value of the character to be displayed. So if the value 65 is given to its
data port the character “A” will be displayed and if the value 49 is given to the LCD the
numeric digit “1” will be displayed. At many instances it is required to display a number like
123 on LCD. Displaying this number is tricky. If the data port of the LCD is loaded with the
number 123, then the character corresponding to it will be displayed.

LCD INTERFACING WITH 8051 IN 8-BIT MODE

Here we use a 16x2 LCD which is interfaced by P89V51RD2 which is a 8051


microcontroller.

Pin configuration is written behind this LCD as...

1 - GND
2 - VCC (+5V)
3 - VEE (FOR CONTRAST)
4 - RS (REGISTER SELECT)
5 - RW (READ/WRITE)
6 - EN (ENABLE)
7-14 - DATA PINS D0-D7
15 - LED PLUS
16 - LED MINUS

Components required:-

1. 10uf electrolytic capacitor


2. 10k ohm registance
3. 10k ohm variable registance
4. 11.059 MHZ crystal oscilltor
5. 16x2 LCD
6. P89V51RD2 IC
7. 5v battery
Circuit diagram:

Platform: P89V51RD2 Development Board (Model No.SK-0001-DB).

Pin Function:-

Port1 is connected to the data port of LCD.

P0.5 is connected to the RS(Register Select) Pin of the LCD.

P0.6 is connected to the R/W(Read/Write) Pin of the LCD.

P0.7 is connected to the E(Enable) Pin of the LCD.


PROGRAM

#include<reg51.h>

#define ldata P2 // port2 is defined as ldata

sbit RS= P0^5; // register select pin is defined

sbit RW= P0^6; //read/write pin is defined

sbit EN= P0^7; //enable pin is defined

unsigned char mess1[]="PHYSICSLAB:"; //message1 to displayed in the 1st line

unsigned char mess2[]="ELECTRONIC "; //message1 to displayed in the 2nd line

unsigned char mess3[]="Implementation"; //message1 to displayed in the 2nd line

unsigned char mess4[]=" "; //message1 to displayed in the 2nd line

/****************************************

function for giving a delay of millisecond

*****************************************/

void delay_ms(unsigned int xtime)

unsigned int i,j;

for(i=0;i<xtime;i++)

for(j=0;j<1275;j++);

/****************************************

function for sending command to lcd

*****************************************/

void lcdcmd(unsigned char value)

{
ldata = value; // value is copied to ldata

RS=0; // since RS=0 "command register" of lcd is selected

RW=0; // since RW=0 lcd goes to write mode

EN=1; // lcd is enabled

delay_ms(1); //delay for 1ms

EN=0; // lcd is disabled

/****************************************

function for sending data to lcd

*****************************************/

void lcddata(unsigned char value)

ldata=value;

RS=1; // since RS=1 "data register" of lcd is selected

RW=0;

EN=1;

delay_ms(1);

EN=0;

/****************************************

function for initializing lcd

*****************************************/

void initialize_lcd()

lcdcmd(0x38); //2 line and 5x7 matrix


delay_ms(10); //delay

lcdcmd(0x0c); // display on cursor off

// lcdcmd(0x0e); // display on cursor blinking

delay_ms(10);

lcdcmd(0x01); //clear display screen

delay_ms(10);

lcdcmd(0x06); //Increament cursor to right

delay_ms(10);

lcdcmd(0x83); //force cursor to position 4th position of line1

delay_ms(10);

void main (void)

unsigned char z,m; // char variable is defined as Z;

initialize_lcd(); // function call to initialize LCD

/*Display Ist message*/

for(z=0;z<11;z++)

lcddata(mess1[z]); // function call for sending data to LCD

while(1)

/*Display 2nd message*/

for(z=0xCF;z>=0xC4;z--)
{

lcdcmd(z);

for( m=0;m<14;m++)

lcddata(mess2[m]);

delay_ms(100);

for(z=0xCF;z>=0xC0;z--)

lcdcmd(z);

for( m=0;m<16;m++)

lcddata(mess4[m]);

delay_ms(100);

lcdcmd(0xc8);

lcddata('&');

delay_ms(100);

lcdcmd(0xc8);

lcddata(' ');

delay_ms(100);

for(z=0xCF;z>=0xC2;z--)
{

lcdcmd(z);

for( m=0;m<14;m++)

lcddata(mess3[m]);

delay_ms(100);

for(z=0xCF;z>=0xC0;z--)

lcdcmd(z);

for( m=0;m<16;m++)

lcddata(mess4[m]);

You might also like