INTERFACING LCD TO 89C51
Liquid crystal display is very important device in embedded system. It offers high flexibility to user as he can display the required data on it. But due to lack of proper approach to LCD interfacing many of them fail. Many people consider LCD interfacing a complex job but according to me LCD interfacing is very easy task, you just need to have a logical approach. This page is to help the enthusiast who wants to interface LCD with through understanding. Copy and Paste technique may not work when an embedded system engineer wants to apply LCD interfacing in real world projects.You will be knowing about the booster rockets on space shuttle. Without these booster rockets the space shuttle would not launch in geosynchronous orbit.
Similarly to understand LCD interfacing you need to have booster rockets attached! To get it done right you must have general idea howto approach any given LCD.This page will help you develop logical approach towards LCD interfacing.
Algorithm to send data to LCD:
LCD Initialization:
My 8051 Development cum
Programmer board
Addresses of cursor position for 16×2 HD44780 LCD
| line1 | 80H | 81H | 82H | 83H | 84H | 85H | 86H | 87H | 88H | 89H | 8AH | 8BH | 8CH | 8DH | 8EH | 8FH |
| line2 | C0H | C1H | C2H | C3H | C4H | C5H | C6H | C7H | C8H | C9H | CAH | CBH | CCH | CDH | CEH | CFH |
Assembly Language Code
; Port0 to higher nibble data pins of LCD
; Crystal 3.579545 MHz
ORG 0000H
AJMP MAIN
ORG 0030H
MAIN:
MOV SP,#60H ;STACK POINTER
ACALL LCD_INIT ;Initialize lcd
MOV DPTR,#MESSAGE1
CALL LCD_STRING ;Display message on LCD
CALL NEXT_LINE ;Place cursor to;second Line
MOV DPTR,#MESSAGE2
CALL LCD_STRING ;Display message on LCD
HERE: AJMP HERE
LCD_INIT: ;initialize LCD in 4-bit mode
ANL P0,#0F0H
CALL LOOP
MOV DPTR,#LCDCODE
MOV A,#0H
MOV R6,#0H
MOV R7,#0H
CLR P2.0 ;RS COMMAND
NEXT: ;8-bit code is split into two 4-bit nibbles.
INC R6
MOVC A,@A+DPTR
MOV R7,A
ANL A,#0F0H
SWAP A
ANL P0,#0F0H
ORL P0,A
ACALL ENABLE ;PULSE E sending first nibble
MOV A,R7
ANL A,#0FH
ANL P0,#0F0H
ORL P0,A
ACALL ENABLE ;PULSE E sending second nibble
MOV A,R6
CJNE R6,#09H,NEXT
RET
LCD_STRING:
MOV P0,#00H
SETB P2.0 ;RS DATA
MOV A,#00H
MOV R6,#00H
NC: ;checks the end of message string
MOVC A,@A+DPTR
CJNE A,#2FH,NC1
RET
NC1:
LCALL LCD_WRITE
INC R6
MOV A,R6
AJMP NC
LCD_WRITE:
SETB P2.0 ;RS DATA
CALL LO
RET
NEXT_LINE:
MOV P0,#00H
CLR P2.0 ;RS COMMAND
MOV A,#0C0H
CALL LO
RET
LCD_CLEAR: ;This Subroutine is used to clear LCD
CALL DELAYL
ANL P0,#00H
MOV A,#01H
CLR P2.0 ; RS command
LO: ;8-bit code is split into two 4-bit nibbles.
MOV R7,A
ANL A,#0F0H
SWAP A
ANL P0,#0F0H
ORL P0,A
CALL ENABLE
MOV A,R7
ANL A,#0FH
ANL P0,#0F0H
ORL P0,A
CALL ENABLE
RET
ENABLE: ;Give High-to-low pulse at enable pin
SETB P2.1
CALL DELAYL
CLR P2.1
CALL DELAYL
RET
;With respect to crystal frequency 3.579 MHz
DELAYL: ; 5ms DELAY
SETB PSW.4 ; SELECT BANK 2
MOV R7,#25
HDH:
MOV R6,#60
DJNZ R6,$
DJNZ R7,HDH
CLR PSW.4 ;DEFAULT BANK
RET
LOOP: ;1 SEC DELAY
MOV R7,#100
LOOP1:
CALL DELAYL
CALL DELAYL
DJNZ R7,LOOP1
RET
;LCD INITIALIZING CODE (DO NOT DISTURB THIS)
DB 02H
DB 02H
DB 02H
DB 28H
DB 28H
DB 28H
DB 0CH
DB 06H
DB 01H
;DATA TO BE DISPLAYED
MESSAGE1: DB “LCD INTERFACING /” ;Change Message1
MESSAGE2: DB ” BY JAYANTH /” ;Change Message2
END









