Sunteți pe pagina 1din 3

9/12/2016

DisplayHELLO!on162LCDusingAT89C51|BraveLearn

Display HELLO! on 162 LCD using AT89C51


Posted on Nov 11, 2014 inAtmel AT89C51

LCD Interfacing with AT89C51


LCD Interfacing with AT89C51 is very common, and usually applied in every engineering project with AT89C51. So, to interface
LCD lets look at some basics:
A 162 LCD means it can display 16 characters per line and there are 2 such lines. In this LCD each character is displayed in 57
pixel matrix. See Pin Configuration:

LCD Pinout

This LCD has two registers.


Command/Instruction Register stores the command instructions given to the LCD. A command is an instruction given to
LCD to do a predefined task like initializing, clearing the screen, setting the cursor position, controlling display etc.
Data Register stores the data to be displayed on the LCD. The data is the ASCII value of the character to be displayed on
the LCD.
Programming the LCD:
To send data on the LCD, data is first written to the data pins with R/W = 0 (to specify the write operation) and RS = 1 (to
select the data register). A high to low pulse is given at EN pin when data is sent. Each write operation is performed on the
positive edge of the Enable signal.
To send a command on the LCD, a particular command is first specified to the data pins with R/W = 0 (to specify the write
operation) and RS = 0 (to select the command register). A high to low pulse is given at EN pin when data is sent.
For more instructions see this table:

http://bravelearn.com/displayhelloon16x2lcdusingat89c51/

1/3

9/12/2016

DisplayHELLO!on162LCDusingAT89C51|BraveLearn

LCD table for functions

Now to display simple HELLO we will first simulate the circuit in Proteus or equivalent software:
Circuit Diagram:

Simulation for LCD interface with AT89C51

Now to run this circuit you first need to create HEX file using Keil or other equivalent software:
Code:
#include reg51.h
//LCD
sbit rs = P3^0;
//register select pin
sbit rw = P3^1;
//read write pin
sbit e = P3^2;
//enable pin
void delay(unsigned int time)
//Function to provide time delay in msec.
{
int i,j ;
for(i=0;i<time;i++)
for(j=0;j<1275;j++);
}
void lcdcmd(unsigned char item)
//Function to send command to LCD
{
P2 = item;
rs= 0;
rw=0;
e=1;
delay(1);
e=0;
return;
}

http://bravelearn.com/displayhelloon16x2lcdusingat89c51/

2/3

9/12/2016
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44

DisplayHELLO!on162LCDusingAT89C51|BraveLearn
void lcddata(double item)
//Function to send data to LCD
{
P2 = item;
rs= 1;
rw=0;
e=1;
delay(1);
e=0;
return;
}
void main()
{
lcdcmd(0x0E);
//turn display ON for cursor blinking
lcdcmd(0x01);
//clear screen
lcdcmd(0x06);
//display ON
lcddata('H');
lcddata('E');
lcddata('L');
lcddata('L');
lcddata('O');
lcddata('!');
while(1){}
//Stuck into infinite loop after displaying HELLO! so to avoid blinking
}

Have a Good Luck! running this simple Project!

http://bravelearn.com/displayhelloon16x2lcdusingat89c51/

3/3

S-ar putea să vă placă și