Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
8051
Written by Amol Shah, on Nov-2007
Views
11987
Symbol
Function
Vss
Ground
Vdd
Supply Voltage
Vo
Contrast Setting
RS
Register Select
R/W
Read/Write Select
En
7-14
DB0-DB7
Data Lines
15
A/Vee
16
For Contrast setting a 10K pot should be used as shown in the figure.
Display Data Ram (DDRAM) stores the display data. So when we have
to display a character on LCD we basically write it into DDRAM. For a
2x16 LCD the DDRAM address for first line is from 80h to 8fh & for
second line is 0c0h to 0cfh. So if we want to display 'H' on the 7th
postion of the first line then we will write it at location 87h.
Now as you have noticed two types of data is given to the LCD data to
be displayed, command or special instruction.So now let us write a
subroutine for both the type of data
Data to be Displayed
lcd_datadisplay:
SETB RS
//Telling the LCD that the data which is being
send is to be displayed
MOV P1,A
SETB EN
CLR EN
CALL DELAY
ret
lcd_command:
CLR RS
send is a command
MOV P1,A
SETB EN
CLR EN
data
CALL DELAY
ret
Here I have used delay at the end of both the subroutines this is done to wait until
the instruction is completely executed by the LCD. This will assure that our program
gives the LCD the time it needs to execute instructions and also makes our program
compatible with any LCD, regardless of how fast or slow it is.
D - Data
The above Table shows the different commands for the LCD. I wont go
into its details.
Before starting to display on LCD we need to Initialize it. Firstly we
must tell the LCD whether we'll be using 8-bit or 4-bit mode. Also we
will be telling the LCD that we need 5x8 character font. Both these
options are selected using a single command i.e. 38h. So to activate
both these options we must execute following instructions:
MOV A,#38h
CALL lcd_command
Now that we have to Turn On the display & set the cursor option i.e.
cursor ON/OFF & Cursor blinking ON/OFF for that we will use the
command 0Eh i.e. Display On , Cursor ON but Cursor blinking OFF.
MOV A,#0Eh
CALL lcd_command
And the last command we require is to configure the LCD in such a way
that everytime we send a character to it the cursor position
automatically increments by one & moves to right i.e. 06h.
MOV A,#06h
CALL lcd_command
lcd_initialize:
MOV A,#38h
CALL lcd_command
MOV A,#38h
CALL lcd_command
MOV A,#38h
CALL lcd_command
ret
lcd_clr:
MOV A,#01h
CALL lcd_command
ret
ORG 0000h
CALL lcd_initialize
CALL lcd_clr
CALL lcd_command
MOV A,#'D'
CALL lcd_datadisplay
MOV A,#'N'
CALL lcd_datadisplay
MOV A,#'A'
CALL lcd_datadisplay
MOV A,#20h
CALL lcd_datadisplay
MOV A,#'T'
CALL lcd_datadisplay
MOV A,#'E'
CALL lcd_datadisplay
MOV A,#'C'
CALL lcd_datadisplay
MOV A,#'H'
CALL lcd_datadisplay
MOV A,#'N'
CALL lcd_datadisplay
MOV A,#'O'
CALL lcd_datadisplay
MOV A,#'L'
CALL lcd_datadisplay
MOV A,#'O'
CALL lcd_datadisplay
MOV A,#'G'
CALL lcd_datadisplay
MOV A,#'Y'
CALL lcd_datadisplay
stop:
ajmp stop
Debugging Procedure
If the above program does not work then follow these steps:1) Check if the supply is correct.
2) If all connections are correct.
3) Increase the delay time.
Check our CODE LIBRARY section for more code.