LCD interfacing with microcontroller is very easy task.You just have to know the proper lcd programming algorithm.

Circuit Diagram

Assembly Language Code

; LCD 16x2 Programming in 4-bit mode.
; Port0 to higher nibble data pins of LCD
; Crystal 3.579545 MHz

; AT89C51

;P2.0 to RS pin

;P2.1 to Enable Pin

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
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)

LCDCODE:
DB 02H
DB 02H
DB 02H
DB 28H
DB 28H
DB 28H
DB 0CH
DB 06H
DB 01H


;DATA TO BE DISPLAYED

;Maximum message length = 16 characters.

;To notify end of message place '/' at the end.

MESSAGE1: DB "LCD INTERFACING /" ;Change Message1

MESSAGE2: DB " IT IS EASY /" ;Change Message2

END



BACK TO MAIN PAGE