lcd and 4x4 keypad interfacing

Status
Not open for further replies.

chaosworm

New Member
Hello everyone! I'm a newbie on 8051 programming and I need some help about lcd and 4x4 keypad interfacing. I'm supposed to make lcd to display the number pressed from the keypad.

I wrote the assembly code below with the help of the Mazidi book but it doesn't work:

ORG 0

CONFIGURE_LCD:
mov a,#38H
acall SEND_COMMAND
mov a,#0FH
acall SEND_COMMAND
mov a,#06H
acall SEND_COMMAND
mov a,#01H
acall SEND_COMMAND
mov a,#80H
acall SEND_COMMAND

SEND_COMMAND:
clr p3.5
clr p3.6
setb p3.7
mov p1,a
acall DELAY
clr p3.7
ret

SEND_DATA:
setb p3.5
clr p3.6
setb p3.7
mov p1,a
acall DELAY
clr p3.7
ret

DELAY:
push 0
push 1
mov r0,#50

DELAY_OUTER_LOOP:
mov r1,#255
djnz r1,$
djnz r0,DELAY_OUTER_LOOP
pop 1
pop 0
ret

MOV P0,#0FFH
K1: MOV P2,#0
MOV A,P0
ANL A,#00001111B
CJNE A,#00001111B,K1
K2: ACALL DELAY
MOV A,P0
ANL A,#00001111B
CJNE A,#00001111B,OVER
SJMP K2
OVER: ACALL DELAY
MOV A,P0
ANL A,#00001111B
CJNE A,#00001111B,OVER1
SJMP K2
OVER1: MOV P2,#11111110B
MOV A,P0
ANL A,#00001111B
CJNE A,#00001111B,ROW_0
MOV P2,#11111101B
MOV A,P0
ANL A,#00001111B
CJNE A,#00001111B,ROW_1
MOV P2,#11111011B
MOV A,P0
ANL A,#00001111B
CJNE A,#00001111B,ROW_2
MOV P2,#11110111B
MOV A,P0
ANL A,#00001111B
CJNE A,#00001111B,ROW_3
LJMP K2

ROW_0: MOV DPTR,#KCODE0
SJMP FIND
ROW_1: MOV DPTR,#KCODE1
SJMP FIND
ROW_2: MOV DPTR,#KCODE2
SJMP FIND
ROW_3: MOV DPTR,#KCODE3
FIND: RRC A
JNC MATCH
INC DPTR
SJMP FIND
MATCH: CLR A
MOVC A,@A+DPTR
MOV P1,A
LJMP SEND_DATA
LJMP K1

ORG 300H

KCODE0: DB '0','1','2','3'
KCODE1: DB '4','5','6','7'
KCODE2: DB '8','9','A','B'
KCODE3: DB 'C','D','E','F'
END

Why it doesn't work? I need to use the same code structure, but where should i change? Thanks in advance..
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…