16x2 LCD Interfacing with 8051 in 8-bit Mode
The most commonly used Character based LCDs are based on Hitachi's HD44780 controller. A 16x2 Character LCD can display 16 Characters in each of two lines. They are available in the market in the name of JHD162A. They operate on a 5V Dc Power supply.
Pin NO |
Name |
Function of the Pin |
1 |
VSS |
Power supply (GND) |
2 |
VCC |
Power supply (+5V) |
3 |
VEE |
Contrast adjust |
4 |
RS |
0 = Instruction Register Select |
5 |
R/W |
0 = Write to LCD module |
6 |
EN |
Enable signal (Clock input) |
7 |
D0 |
Data bus line 0 (LSB) |
8 |
D1 |
Data bus line 1 |
9 |
D2 |
Data bus line 2 |
10 |
D3 |
Data bus line 3 |
11 |
D4 |
Data bus line 4 |
12 |
D5 |
Data bus line 5 |
13 |
D6 |
Data bus line 6 |
14 |
D7 |
Data bus line 7 (MSB) / Busy Flag Check |
15 |
LED+ |
+5V supply for the LED Backlight |
16 |
LED- |
Ground for the LED Backlight |
The contrast can be adjusted by using a Potentiometer to provide a voltage between 0V to 5 V to the VEE, with 0, means Highest Contrast.
The Initialization routine (The algorithm to interface the LCD With 8051 in 8 bit Mode with checking busy flag:)
:
The Schematic of Interfacing LCD with 8051 in 8 bit mode
Assembly code for Busy Flag Checking and LCD Interfacing in 8-bit mode:
;lcd interfacing to at89c51 in 8-bit mode
;with busy flag checking
RS BIT P2.0 ;define the pins we are going
RW BIT P2.1 ;to use in our code
EN BIT P2.2 ;for simplicity
BF BIT P1.7
MOV A, #38H ;8 bit 2 line display 5x7 font
ACALL SEND_CMD ;call the instruction write sub-routine
MOV A, #0EH ;lcd on cursor on
ACALL SEND_CMD
MOV A, #01H ;clear lcd
ACALL SEND_CMD
MOV A, #06H ;cursor position auto increment move cursor to right
ACALL SEND_CMD
MOV A, #'E'
ACALL SEND_DATA ;call the data write sub routine
MOV A, #'S'
ACALL SEND_DATA
MOV A, #'R'
ACALL SEND_DATA
MOV A, #'T'
ACALL SEND_DATA
MOV A, #'.'
ACALL SEND_DATA
MOV A, #' '
ACALL SEND_DATA
HERE: SJMP HERE ;wait here indefinitely
SEND_CMD: ;the sub-routine to write command to the instruction register
ACALL READY ;goto busy-flag check subroutine, to determine if lcd is ready
MOV P1, A
CLR RS ;select the instruction register
CLR RW ;going to write command
SETB EN ;initiate high to low pulse on enable
CLR EN
RET
SEND_DATA: ;the sub-routine to write data to the instruction register
ACALL READY
MOV P1, A
SETB RS ;select data register
CLR RW ;going to write data
SETB EN ;initiate high to low pulse on enable
NOP
CLR EN
RET
;subroutine to check busy-flag and determine if the lcd is ready for next operation
READY: SETB BF ;make the bf pin logic 1
CLR RS ;select command register
SETB RW ;going to read
BACK: CLR EN ;initiate low to high transition on enable pin
NOP
SETB EN
JB BF, BACK ;keep checking busy flag, till it becomes logic 0
RET ;return from the ready sub-routine
END
The Assembly code and the Proteus Simulation file can be downloaded from here (zip) or here (rar)