Documente Academic
Documente Profesional
Documente Cultură
AIM/OBJECTIVE:
The objective is to interface an output device such as an LCD using 8051 microcontroller.
EQUIPMENT REQUIRED:
One LCD: LM016L
One uC: AT89C51
SOFTWARE USED:
SUMMARY ON DATASHEET:
HD44780U is a 16*2 bit LCD device. The input voltage range is from 2.7 to 5.5V.The LCD chip used in here has 14
pins. While Vcc and Vss provide +5V and ground respectively, V EE is used for controlling the contrast. The pin
description as listed below:
Pin
1
2
3
4
Symbol
Vss
Vcc
VEE
RS
I/O
I
R/W
6
7-14
E
DB0-DB7
I/O
I/O
Description
Ground
+5V Supply
Controls contrast
RS=0: Command Register
RS=1: Data Register
R/W=0:
Write
R/W=1: Read
Enable
The 8-Bit Data bus
THEORY:
. LCD is fast replacing LED for displaying data as it can display not only numbers unlike LED but can also print out
Alphabets and other characters using their ASCII values. Moreover, with the decrease in their prices, there is no
moving back for LCDs. An LCD has 2 registers of importance; Data Register and Instruction command register. The
RS pin select is used to differentiate between command signal and data signal according to the configuration
discussed in Datasheet. R/W pin is used to either write or read the LCD. Enable pin is used to latch the data present
at the data pins of the LCD chip. When data is supplied, the enable pin must undergo a high to low transition to latch
the data.
1 | Page
There are 8 I/O data pins to send and receive information to and from the LCD. RS pin along with R/W pin is used
to monitor the Busy flag. When RS=0 along with R/W=1 and if Busy flag status is 1, the LCD wont accept any new
information and would carry on its own internal functions.
PROCEDURE:
The LCD and microcontroller were connected according to Fig 1. They were then connected to the Virtual
Terminal.
The program was written in Keil and was embedded in the microcontroller.
Port 1 of the microcontroller was assigned the pins like Enable, RS and R/W to perform specific functions
on the LCD.
Port 2 of the microcontroller was connected to the data bus of the LCD for either information or data
PROGRAM CODE:
ENABLE
BIT P1.1
RS
BIT P1.0
DATAPORT EQU P2
ORG 000
MAIN:
ACALL DELAY
// Call Delay
ACALL SETUP_SERIAL
MOV DPTR,#INIT_TEXT
ACALL SEND_LINE
ACALL INIT_LCD
// initialize LCD
MOV DPTR,#MY_TEXT
AGAIN_PRINT:
// Print to LCD
CLR A
MOVC A,@A+DPTR
ACALL SEND_DATA
INC DPTR
JNZ AGAIN_PRINT
2 | Page
MOV DPTR,#DONE_TEXT
ACALL SEND_LINE
//MOV A,#"J"
//ACALL SEND_CHAR
HERE:ACALL RCV_CHAR
CJNE A,#27,NEXT
ACALL CLR_LCD
SJMP HERE
NEXT:ACALL SEND_DATA
SJMP HERE
WAIT:SJMP WAIT
CLR_LCD:
MOV A,#01H
ACALL SEND_CMD
RET
INIT_LCD:
MOV A,#38H
ACALL SEND_CMD
MOV A,#0EH
ACALL SEND_CMD
MOV A,#01H
//CLEAR LCD
ACALL SEND_CMD
MOV A,#06H
ACALL SEND_CMD
MOV A,#80H
ACALL SEND_CMD
RET
SEND_CMD:
MOV DATAPORT,A
CLR RS
3 | Page
//Set as instruction
ACALL ENABLE_R
RET
SEND_DATA:
MOV DATAPORT,A
SETB RS
//Set as Data
ACALL ENABLE_R
RET
ENABLE_R:
CLR ENABLE
//ACALL DELAY
SETB ENABLE
ACALL DELAY
CLR ENABLE
//ACALL DELAY
RET
DELAY:
//Delay function
MOV R6,1
DEL1:
MOV R7,100
DEL0:DJNZ R7,DEL0
DJNZ R6,DEL1
RET
SETUP_SERIAL:
MOV TMOD,#20H //TIMER1 MODE2(for serial) and TIMER0 MODE2(auto-reload mode for
generating clock of ~10KHz for ADC 0808)
//9600 BAUD
MOV SCON,#50H
SETB TR1
CLR RI // clear RI for the 1st reception
4 | Page
RET
RCV_CHAR:
SEND_CHAR:
MOV SBUF,A
WAIT2SEND:JNB TI,WAIT2SEND
CLR TI
RET
SEND_LINE:
CLR A
MOVC A,@A+DPTR
ACALL SEND_CHAR
INC
DPTR
JNZ SEND_LINE
RET
MY_TEXT: DB "NIT RKL",0
INIT_TEXT: DB "INITIALIZING....",0
DONE_TEXT: DB "DONE",13,"TYPE YOUR TEXT BELOW :-" ,13,13,0
END
RESULTS:
5 | Page
6 | Page
CONCLUSION:
The LCD was successfully interfaced by using the 8051 microcontroller. Sentences, Numbers and special characters
were tested. Even a few instructions were loaded which worked perfectly.
7 | Page