8051 INTERFACE WITH LCD USING ASSEMBLY
16xX , 20xX , and some other size lcds use in many projects . so it is very important for embedded . project . here is very simple way to use the lcd
DESCRIPTIONS:
WRITE DATA TO LCD :
Make R\W pin low
Make RS 1
Keep data on data port of lcd
High to low pulse on ENABLE pin
WRITE COMMAND TO LCD:
Make R/W pin low
Make RS 0 , low
Keep command instruction hex on data port of lcd
High to low pulse ENABLE pin
SOME EXAMPLES:
THAT IS very easy examples to under stand the working of the lcd . if you want send the data to lcd then keep the word in ASCII on data port of lcd and use the data write sequence .if want send the command to lcd then keep command instruction on data port and use the sequence of command .
EXAMPLE1: CLEAR THE SCREEN
MOV A , #01H
ACALL COMMAND
MOV A , #02H
ACALL COMMAND
EXAMPLE2: WRITE DATA TO LCD
MOV A , #'A'
ACALL DISPLAY
MOV A , #'B'
MOV A , #'B'
ACALL DISPLAY
EXAMPLE3: WRITE DATA
MOV A , #' ' IF want write word on lcd then write any word here
ACALL DISPLAY
COMMAND PROGRAM SUB ROUTINE :
COMMAND: MOV P1 ,A
CLR P2.0
SETB P2.1
ACALL DELAYLCD
CLR P2.1
RET
DISPLAY PROGRAM SUB ROUTINE :
DISPLAY: MOV P1 , A
SETB P2.0 ; P2.0 FOR RS PIN
SETB P2.1 ; FOR ENABLE PIN
ACALL DELAYLCD
CLR P2.1
CLR P2.0
RET
WE can use some other pin for RS and ENABLE
BASIC PROGRAM FOR LCD INITIALIZE :
ORG 00H
MAIN: MOV P1 , #00H
MOV P2 , #00H
MOV A,#38H ; Use 2 lines and 5x7 matrix
ACALL COMMAND
MOV A,#0FH ; LCD ON cursor ON
ACALL COMMAND
MOV A,#01H ;Clear screen
ACALL COMMAND
ASSEMBLY PROGRAM FOR LCD INTERFACING
ORG 00H
MAIN: MOV P1 , #00H
MOV P2 , #00H
MOV A,#38H ; Use 2 lines and 5x7 matrix
ACALL COMMAND
MOV A,#0FH ; LCD ON cursor ON
ACALL COMMAND
MOV A,#01H ;Clear screen
ACALL COMMAND
HERE: MOV A , #'I'
ACALL DISPLAY
MOV A , #0C5H
ACALL DISPLAY
MOV A , #'L'
ACALL DISPLAY
MOV A , #'O'
ACALL DISPLAY
MOV A , #'V'
ACALL DISPLAY
MOV A , #'E'
ACALL DISPLAY
MOV A , #82H
ACALL COMMAND
MOV A , #'E'
ACALL DISPLAY
MOV A , #'L'
ACALL DISPLAY
MOV A , #'E'
ACALL DISPLAY
MOV A , #'C'
ACALL DISPLAY
MOV A , #'T'
ACALL DISPLAY
MOV A , #'R'
ACALL DISPLAY
MOV A , #'O'
ACALL DISPLAY
MOV A , #'N'
ACALL DISPLAY
MOV A , #'I'
ACALL DISPLAY
MOV A , #'C'
ACALL DISPLAY
ACALL DELAY
ACALL CLEAR
MOV A , #'P'
ACALL DISPLAY
MOV A , #'R'
ACALL DISPLAY
MOV A , #'E'
ACALL DISPLAY
MOV A , #'S'
ACALL DISPLAY
MOV A , #'E'
ACALL DISPLAY
MOV A , #'N'
ACALL DISPLAY
MOV A , #'T'
ACALL DISPLAY
MOV A , #'E'
ACALL DISPLAY
MOV A , #'L'
ACALL DISPLAY
MOV A , #'E'
ACALL DISPLAY
MOV A , #'C'
ACALL DISPLAY
MOV A , #'T'
ACALL DISPLAY
MOV A , #'R'
ACALL DISPLAY
MOV A , #'O'
ACALL DISPLAY
MOV A , #'N'
ACALL DISPLAY
MOV A , #'I'
ACALL DISPLAY
MOV A , #'C'
ACALL DISPLAY
MOV A , #80H
ACALL COMMAND
MOV A , #'.'
ACALL DISPLAY
MOV A , #'B'
ACALL DISPLAY
MOV A , #'L'
ACALL DISPLAY
MOV A , #'O'
ACALL DISPLAY
MOV A , #'G'
ACALL DISPLAY
MOV A , #'S'
ACALL DISPLAY
MOV A , #'P'
ACALL DISPLAY
MOV A , #'O'
ACALL DISPLAY
MOV A , #'T'
ACALL DISPLAY
MOV A , #'.'
ACALL DISPLAY
MOV A , #'C'
ACALL DISPLAY
MOV A , #'O'
ACALL DISPLAY
MOV A , #'M'
ACALL DISPLAY
ACALL DELAY
ACALL CLEAR
AJMP HERE
CLEAR: MOV A , #01H
ACALL COMMAND
MOV A , #02H
ACALL COMMAND
RET
DISPLAY: MOV P1 , A
SETB P2.0 ; P2.0 FOR RS PIN
SETB P2.1 ; FOR ENABLE PIN
ACALL DELAYLCD
CLR P2.1
CLR P2.0
RET
COMMAND: MOV P1 ,A
CLR P2.0
SETB P2.1
ACALL DELAYLCD
CLR P2.1
RET
DELAY: MOV R2, #01Ch
MOV R1, #0EDh
MOV R0, #0E0h
NOP
DJNZ R0, $
DJNZ R1, $-5
DJNZ R2, $-9
MOV R0, #0DDh
DJNZ R0, $
RET
DELAYLCD: MOV R2, #004h
MOV R1, #0A0h
MOV R0, #04Ch
NOP
DJNZ R0, $
DJNZ R1, $-5
DJNZ R2, $-9
MOV R0, #049h
DJNZ R0, $
RET
END
No comments:
Post a Comment