LCD Interfacing With 8051 and LCD With KEYPAD Interfacing With 8051
LCD Interfacing With 8051 and LCD With KEYPAD Interfacing With 8051
LCD Interfacing With 8051 and LCD With KEYPAD Interfacing With 8051
Submitted by
code:
ORG 0H
MOV TMOD,#10H
MOV A,#38H ; INIT THE LCD
ACALL COMWRT
ACALL DELAY
MOV A,#0EH
ACALL COMWRT
ACALL DELAY
MOV A,#01H
ACALL COMWRT
ACALL DELAY
MOV A,#06H
ACALL COMWRT
ACALL DELAY
MOV A,#3CH ; TO ACTIVATE SECOND LINE
ACALL COMWRT
ACALL DELAY
MOV A,#0C0H
ACALL COMWRT
ACALL DELAY
; NOW WE ARE READY TO SEND THE DATA "CODE"
MOV A, #'C'
ACALL DATAWRT
ACALL DELAY
MOV A, #'O'
ACALL DATAWRT
ACALL DELAY
MOV A, #'D'
ACALL DATAWRT
ACALL DELAY
MOV A, #'E'
ACALL DATAWRT
ACALL DELAY
HERE: SJMP HERE
COMWRT:
MOV P1,A ; PORT P1 DATA LINE AND PORT P2 COMMAND LINE
CLR P2.0
CLR P2.1
SETB P2.2
CLR P2.2
RET
DATAWRT:
MOV P1,A ; PORT P1 DATA LINE AND PORT P2 COMMAND LINE
SETB P2.0
CLR P2.1
SETB P2.2
CLR P2.2
RET
DELAY:
;TIMER 1 IN MODE 1 MAXIMUM DELAY
MOV TH1,#0H
MOV TL1,#0H
SETB TR1
BACK: JNB TF1,BACK
CLR TF1
CLR TR1
RET
END
CODE:
ORG 0H
START:
ACALL LCDINIT
ACALL GETKEY
AGAIN: SJMP AGAIN
LCDINIT: MOV A,#38H ;INIT. LCD 2 LINES, 5X7 MATRIX
ACALL COMNWRT ;call command subroutine
ACALL DELAY ;give LCD some time
MOV A,#0EH ;display on, cursor on
ACALL COMNWRT ;call command subroutine
ACALL DELAY ;give LCD some time
MOV A,#01 ;clear LCD
ACALL COMNWRT ;call command subroutine
ACALL DELAY ;give LCD some time
MOV A,#06H ;shift cursor right
ACALL COMNWRT ;call command subroutine
ACALL DELAY ;give LCD some time
MOV A,#80H ;cursor at line 1, pos. 4
ACALL COMNWRT ;call command subroutine
ACALL DELAY ;give LCD some time
MOV A,#'K' ;display letter N
ACALL DATAWRT ;call display subroutine
ACALL DELAY ;give LCD some time
MOV A,#'E' ;display letter O
ACALL DATAWRT ;call display subroutine
ACALL DELAY ;give LCD some time
MOV A,#'Y' ;display letter O
ACALL DATAWRT ;call display subroutine
ACALL DELAY ;give LCD some time
MOV A,#':' ;display letter O
ACALL DATAWRT ;call display subroutine
ACALL DELAY ;give LCD some time
RET
COMNWRT:MOV P1,A
CLR P2.0
CLR P2.1
SETB P2.2
ACALL DELAY
CLR P2.2
RET
DATAWRT:MOV P1,A
SETB P2.0
CLR P2.1
SETB P2.2
ACALL DELAY
CLR P2.2
RET
DELAY:MOV R3,#50 ;50 or higher for fast CPUs
HERE2:MOV R4,#255 ;R4 = 255
HERE:DJNZ R4,HERE ;stay until R4 becomes 0
DJNZ R3,HERE2
RET
;Keyboard subroutine. This program sends the ASCII
;Code for pressed key to P0.1
;P0.4-P0.7 connected to rows, P0.0-P0.3 to column