org 0h
;keypad --> port1
;LCD --> port2
;RS --> p0.0
;R/W --> p0.1
;E --> p0.2
main:
mov r5,#2d
again:
mov p1,#00000111b
mov a,p1
anl a,#00000111b
cjne a,#00000111b,again
again1:
acall delay
mov a,p1
anl a,#00000111b
cjne a,#00000111b,check
sjmp again1
check:
mov a,p1
anl a,#00000111b
cjne a,#00000111b,check1
sjmp again1
check1:
mov p1,#11110111b
mov a,p1
anl a,#11110111b
cjne a,#11110111b,row0
mov p1,#11101111b
mov a,p1
anl a,#11101111b
cjne a,#11101111b,row1
mov p1,#11011111b
mov a,p1
anl a,#11011111b
cjne a,#11011111b,row2
mov p1,#10111111b
mov a,p1
anl a,#10111111b
cjne a,#10111111b,row3
ljmp again1
row0:
mov dptr,#code0
sjmp find
row1:
mov dptr,#code1
sjmp find
row2:
mov dptr,#code2
sjmp find
row3:
mov dptr,#code3
sjmp find
find:
rrc a
jnc match
inc dptr
sjmp find
match:
clr a
movc a,@a+dptr
mov r2,a
/// here the pointer stuck on "acall display_start" and dont go for djnz
acall display_start
//using djnz to take input twice and display two digits on the LCD
// r5 is loaded with the value two as mentioned above.. mov r5,#2d
djnz r5,again
delay:
mov r0,#72
label:
mov r1,#255
label1:
djnz r1,label1
djnz r0,label
ret
display_start:
mov a,#38h
acall command
mov a,#0eh
acall command
mov a,#01h
acall command
mov a,#06h
acall command
mov a,#86h
acall command
mov a,r2
acall display
ret
command: acall ready
mov p2,a
clr p0.0
clr p0.1
setb p0.2
clr p0.2
ret
display: acall ready
mov p2,a
setb p0.0
clr p0.1
setb p0.2
acall delay1
clr p0.2
ret
ready: setb p2.7
clr p0.0
setb p0.1
back: clr p0.2
acall delay1
setb p0.2
jb p2.7,back
ret
delay1: mov r3,#50
here:
mov r4,#255
here2:
djnz r4,here2
djnz r3,here
ret
org 300h
code0: db "1","2","3"
code1: db "4","5","6"
code2: db "7","8","9"
code3: db 2Ah,"0",23h
end
the format of the code is wrong. before using a device under stand the basics first. start your project with step by step process. first start with lcd, lcd has to be initialized before it has to be used. display the project name and then proceed to scan the keypad. either use pull ups in p0 or use p3 for RS, RW, EN.
all the best
org 0h
;keypad --> port1
;LCD --> port2
;RS --> p0.0
;R/W --> p0.1
;E --> p0.2
mov a,#38h
acall command // here the code stuck when i debug the code
mov a,#0eh
acall command
mov a,#01h
acall command
mov a,#06h
acall command
mov a,#86h
acall command
again:
mov p1,#00000111b
mov a,p1
anl a,#00000111b
cjne a,#00000111b,again
again1:
acall delay
mov a,p1
anl a,#00000111b
cjne a,#00000111b,check
sjmp again1
check:
mov a,p1
anl a,#00000111b
cjne a,#00000111b,check1
sjmp again1
check1:
mov p1,#11110111b
mov a,p1
anl a,#11110111b
cjne a,#11110111b,row0
mov p1,#11101111b
mov a,p1
anl a,#11101111b
cjne a,#11101111b,row1
mov p1,#11011111b
mov a,p1
anl a,#11011111b
cjne a,#11011111b,row2
mov p1,#10111111b
mov a,p1
anl a,#10111111b
cjne a,#10111111b,row3
ljmp again1
row0:
mov dptr,#code0
sjmp find
row1:
mov dptr,#code1
sjmp find
row2:
mov dptr,#code2
sjmp find
row3:
mov dptr,#code3
sjmp find
find:
rrc a
jnc match
inc dptr
sjmp find
match:
clr a
movc a,@a+dptr
mov r2,a
acall on_lcd
ljmp again
delay:
mov r0,#72
label:
mov r1,#255
label1:
djnz r1,label1
djnz r0,label
ret
/*
display_start:
mov a,#38h
acall command
mov a,#0eh
acall command
mov a,#01h
acall command
mov a,#06h
acall command
mov a,#86h
acall command
ret
*/
on_lcd:
mov a,r2
acall display
ret
command: acall ready
mov p2,a
clr p0.0
clr p0.1
setb p0.2
clr p0.2
ret
display: acall ready
mov p2,a
setb p0.0
clr p0.1
setb p0.2
acall delay1
clr p0.2
ret
ready:
setb p2.7
clr p0.0
setb p0.1
back: clr p0.2
acall delay1
setb p0.2
jb p2.7,back
ret
delay1: mov r3,#50
here:
mov r4,#255
here2:
djnz r4,here2
djnz r3,here
ret
org 300h
code0: db "1","2","3"
code1: db "4","5","6"
code2: db "7","8","9"
code3: db 2Ah,"0",23h
end
Rs equ p1.2
rw equ p1.1
en equ p1.0
busy bit p0.7
dat equ p0
org 0h
jmp main
org 30h
main:
Call linit
mov dptr,#mes1
call messdisp
mov a,#'o'
call datawrt
mov a,#'k'
call datawrt
jmp $
linit:
Clr rw
mov a,#38h ;lcd 2 lines
call comnwrt
call clears
call sline
mov a,#0ch ;display on cursor on
call comnwrt
mov a,#6h ;shift cursor right
call comnwrt
fline:
Mov a,#80h ;send first line address
call comnwrt
ret
sline:
Mov a,#0c0h ;send first line address
call comnwrt
ret
clears:
Mov a,#01h ;clear display
call comnwrt
ret
comnwrt:
Call ready
mov dat,a
clr rs
setb en
clr en
ret
datawrt:
Call ready
mov dat,a
setb rs
setb en
clr en
ret
ready:
Setb busy
setb rw
clr rs
c1:
Clr en
nop
nop
setb en
jb busy,c1
clr rw
ret
messdisp:
D1:clr a
movc a,@a+dptr
cjne a,#0ffh,cont
ret
cont:
Call datawrt
inc dptr
sjmp d1
delay:
Mov r7,#10d
l2: Mov r6,#100d
l1:
Call del
djnz r6,l1
djnz r7,l2
ret
del:
Clr cprl2
clr ct2
mov tl2,#7ch
mov th2,#0fch
setb tr2
jnb tf2,$
clr tr2
clr tf2
ret;
mes1: Db "testing ",255
end
org 0h
//timer initialization
mov tmod,#20h
mov th1,#0fah
mov scon,#50h
setb tr1
clr ti
//***********
mov r5,#3
//LCD initialization
mov a,#38h
acall command
mov a,#0eh
acall command
mov a,#01h
acall command
mov a,#06h
acall command
mov a,#86h
acall command
here1:
acall again
mov a,r2
acall send
acall display
djnz r5,here1
mov r5,#3
mov a,#0c6h
acall command
repeat:
acall again
mov a,r2
acall display
djnz r5,repeat
sjmp $
command: acall ready
mov p2,a
clr p0.0
clr p0.1
setb p0.2
clr p0.2
ret
display: acall ready
mov p2,a
setb p0.0
clr p0.1
setb p0.2
acall delay
clr p0.2
ret
ready: setb p2.7
clr p0.0
setb p0.1
back: clr p0.2
acall delay
setb p0.2
jb p2.7,back
ret
//****************
//SEND
send:
mov sbuf,a
stay: jnb ti,stay
clr ti
ret
//***************
//KEYPAD routine
again:
mov p1,#00000111b
mov a,p1
anl a,#00000111b
cjne a,#00000111b,again
again1:
acall delay1
mov a,p1
anl a,#00000111b
cjne a,#00000111b,check
sjmp again1
check:
mov a,p1
anl a,#00000111b
cjne a,#00000111b,check1
sjmp again1
check1:
mov p1,#11110111b
mov a,p1
anl a,#11110111b
cjne a,#11110111b,row0
mov p1,#11101111b
mov a,p1
anl a,#11101111b
cjne a,#11101111b,row1
mov p1,#11011111b
mov a,p1
anl a,#11011111b
cjne a,#11011111b,row2
mov p1,#10111111b
mov a,p1
anl a,#10111111b
cjne a,#10111111b,row3
ljmp again1
row0:
mov dptr,#code0
sjmp find
row1:
mov dptr,#code1
sjmp find
row2:
mov dptr,#code2
sjmp find
row3:
mov dptr,#code3
sjmp find
find:
rrc a
jnc match
inc dptr
sjmp find
match:
clr a
movc a,@a+dptr
mov r2,a
//LCD delay
delay: mov r3,#50
here:
mov r4,#255
here2:
djnz r4,here2
djnz r3,here
ret
//KEYPAD delay
delay1:
mov r0,#72
label:
mov r1,#255
label1:
djnz r1,label1
djnz r0,label
ret
org 300h
code0: db "1","2","3"
code1: db "4","5","6"
code2: db "7","8","9"
code3: db 2Ah,"0",23h
//************
end
org 0h
mov tmod,#20h
mov th1,#0fah
mov scon,#50h
setb tr1
clr ri
mov r5,#3
mov a,#38h
acall command
mov a,#0eh
acall command
mov a,#01h
acall command
mov a,#06h
acall command
mov a,#86h
acall command
repeat:
acall recv
acall display
djnz r5,repeat
mov r5,#3
mov a,#0c6h
acall command
here1:
acall recv
acall display
djnz r5,here1
recv:
stay:jnb ri,stay
mov a,sbuf
clr ri
ret
command: acall ready
mov p2,a
clr p0.0
clr p0.1
setb p0.2
clr p0.2
ret
display: acall ready
mov p2,a
setb p0.0
clr p0.1
setb p0.2
acall delay
clr p0.2
ret
ready: setb p2.7
clr p0.0
setb p0.1
back: clr p0.2
acall delay
setb p0.2
jb p2.7,back
ret
delay: mov r3,#50
here:
mov r4,#255
here2:
djnz r4,here2
djnz r3,here
ret
end
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?