You are on page 1of 14

INTERFACING LCD DISPLAY TO 8051 MICROCONTROLLER

Hammad Khan (191216)


_________________________

BACHELOR OF ELECTRICAL ENGINEERING


Fall-19

Submitted To:
Engr. Mariam Sabir
Lab Engineer
____________

Department of Electrical Engineering


FACULTY OF ENGINEERING
AIR UNIVERSITY,ISLAMABAD
AIR UNIVERSITY
DEPARTMENT OF ELECTRICAL AND COMPUTER ENGINEERING

EXPERIMENT NO 5

Lab Title: Interfacing LCD to Microcontroller

Student Name: Hammad Khan Reg. No: 191216

Objective: Interfacing LCD to microcontroller to make students capable of using LCD as data
displaying device to give their projects a more professional look

LAB ASSESSMENT:

Excellent Good Average Satisfactory Unsatisfactory


Attributes (5) (4) (3) (2) (1)
Ability to Conduct
Experiment
Ability to assimilate the
results
Effective use of lab
equipment and follows
the lab safety rules

Total Marks: Obtained Marks:

LAB REPORT ASSESSMENT:

Excellent Good Average Satisfactory Unsatisfactory


Attributes
(5) (4) (3) (2) (1)

Data presentation

Experimental results

Conclusion

Total Marks: Obtained Marks:

Date: 28-10-2021 Signature:


Lab#05
INTERFACING LCD DISPLAY TO 8051
MICROCONTROLLER
Objective:
 Interfacing LCD to microcontroller to make students capable of using LCD as data
displaying device to give their projects a more professional look

Equipment:
Hardware:
1. 89c51 microcontroller
2. LEDs
Software:
1. Keil u-vision
2. Smart-pro 5000u

Discussion:
Most projects you create with the 8051 CPU require some form of display. The most common
way to accomplish this is with the LCD (Liquid Crystal Display). LCDs have become a cheap
and easy way to get text display for embedded system Common displays are set up as 16 to 20
characters by 1 to 4 lines.
LCD Display:
Pin Configuration of LCD:
PINOUT: • 8 data pins D7:D0
Bi-directional data/command pins. Alphanumeric characters are sent in ASCII format. • RS:
Register Select
RS = 0 -> Command Register is selected
RS = 1 -> Data Register is selected
• R/W: Read or Write
R/W= 0 -> Write
R/W= 1 -> Read
• E: Enable (Latch data)
Used to latch the data present on the data pins. A high-to-low edge is needed to latch the data. •
VEE : contrast control
NOTE: When writing to the display, data is transferred only on the high to low transition of this
signal. However, when reading from the display, data will become available shortly after the low
to high transition and remain available until the signal falls low again. Display Data RAM
(DDRAM) Display data RAM (DDRAM) is where you send the characters (ASCII code) you
want to see on the LCD screen. It stores display data represented in 8-bit character codes. Its
capacity is 80 characters (bytes). Below you see DD RAM address layout of a 2*16 LCD

In the above memory map, the area shaded in black is the visible display (For 16x2 display). For
first line addresses for first 15 characters is from 00h to 0Fh. But for second line address of first
character is 40h and so on up to 4Fh for the 16th character. So if you want to display the text at
specific positions of LCD, we require to manipulate address and then to set cursor position
accordingly
Character Generator RAM (CGRAM)-User defined character RAM
LCD Commands The LCD’s internal controller accept several commands and modify the display
accordingly. These commands would be things like:
Clear screen
Return home
Shift display right/lef
INTERFACING LCD TO 8051
The 44780 standard requires 3 control lines as well as either 4 or 8 I/O lines for the data bus. The
user may select whether the LCD is to operate with a 4-bit data bus or an 8-bit data bus.
The three control lines are EN, RS, and RW. Note that the EN line must be raised/lowered
before/after each instruction sent to
the LCD regardless of whether that instruction is read or write, text or instruction. In short, you
must always manipulate EN when communicating with the LCD. EN is the LCD's way of
knowing that you are talking to it. If you don't raise/lower EN, the LCD doesn't know you're
talking to it on the other lines.
EXERCISE
Task#01
Display a string on screen by using C code.
Program Code
#include <stdlib.h>
#include <stdio.h>
#include <reg52.h>
sbit RS = P2^0;
sbit RW = P2^1;
sbit EN = P2^2;
void Delay(unsigned int x)
{
int i;
for(i=0 ; i<x ; i++);
}
void Data( unsigned char A){
P1=A;
RS =1;
RW = 0;
EN = 1;
Delay(10000);
EN = 0;
}
void Command(unsigned int A)
{
P1 = A;
RS=0; //RS
RW=0; //R/W
EN=1; //Enable
Delay(10000);
EN = 0;
}
void main()
{
char A[15]="HAMMAD";
int i = 0;
Command(0x38);
Command(0x0E);
Command(0x01);
Command(0x06);
while(A[i] !='\0'){
Data(A[i]);
i++;
Delay(1000);
}
}

Proteus Circuit
Task#02
Display a string on screen and blink the entire display 5 times.

Program Code
#include<reg51.h>
#define display_port P2
sbit rs = P3^2;
sbit rw = P3^3;
sbit e = P3^4;
void msdelay(unsigned int time)
{ unsigned i,j ;
for(i=0;i<time;i++)
for(j=0;j<1275;j++);
}
void lcd_cmd(unsigned char command)
{display_port = command;
rs= 0;
rw=0;
e=1;
msdelay(1);
e=0;
}void lcd_data(unsigned char disp_data)
{display_port = disp_data;
rs= 1;
rw=0;
e=1;
msdelay(1);
e=0;
}
void lcd_init()
{
lcd_cmd(0x0F);
msdelay(10);
lcd_cmd(0x08);
msdelay(50);
lcd_cmd(0x81);
msdelay(10);
}
void main()
{
unsigned char a[15]="HAMMAD";
int l=0;
lcd_init();
while(a[l] != '\0')
{lcd_data(a[l]);
l++;
msdelay(50);
}
}
Proteus Circuit
Task#03
Display a string on screen and shift right
Code
#include <stdlib.h>
#include <stdio.h>
#include <reg52.h>
sbit RS = P2^0;
sbit RW = P2^1;
sbit EN = P2^2;
void Delay(unsigned int x)
{
int i;
for(i=0 ; i<x ; i++);
}
void Data( unsigned char A){
P1=A;
RS =1;
RW = 0;
EN = 1;
Delay(10000);
EN = 0;
}

void Command(unsigned int A)


{
P1 = A;
RS=0; //RS
RW=0; //R/W
EN=1; //Enable
Delay(10000);
EN = 0;
}
void main()
{
char A[15]="HAMMAD";
int i = 0;
Command(0x38);
Command(0x0E);
Command(0x01);
Command(0x06);
while(A[i] !='\0'){
Data(A[i]);
i++;
Delay(1000);
Command(0x1E);
}
}
Proteus Circuit
Task#04
Display a character on screen and make the display to do too and fro motion within LCD
display space.
Code
#include <stdlib.h>
#include <stdio.h>
#include <reg52.h>
sbit RS = P2^0;
sbit RW = P2^1;
sbit EN = P2^2;
void Delay(unsigned int x)
{
int i;
for(i=0 ; i<x ; i++);
}
void Data( unsigned char A){
P1=A;
RS =1;
RW = 0;
EN = 1;
Delay(10000);
EN = 0;
}
void Command(unsigned int A)
{
P1 = A;
RS=0;
RW=0;
EN=1;
Delay(10000);
EN = 0;
}
void main()
{
char A[15]="HAMMAD";
int i = 0;
Command(0x38);
Command(0x0E);
Command(0x01);
Command(0x06);
while(A[i] !='\0'){
Data(A[i]);
i++;
Delay(1000);
Command(0x1E);
Delay(1000);
Command(0x18);
}
}
Proteus Circuit
Learning Outcomes:
In this lab, we learnt about interfacing LCD using microcontroller and display our desired output.
We learned about commands and modes of LCD. LCD accepts two inputs one is for commands.
Commands are used to control the features of LCD. And second is Data which is used to display
our desired result on LCD.

You might also like