start:
call disp
lcall keyscan
cjne a,#0ffh,nex
sjmp start
nex:
mov 20h,a
sjmp start
;显示函数,显示从20h开始的3个单元的内容
disp:
mov r0,#20h
mov r1,#1
mov r2,#01
lop:
mov a,@r0
lcall displ
mov a,@r0
lcall disph
inc r0
djnz r1,lop
ret
disph:
swap a
displ:
anl a,#0fh
mov dptr,#tab
movc a,@a+dptr
mov dptr,#pb
movx @dptr,a
mov a,r2
mov dptr,#pa
movx @dptr,a
rl a
mov r2,a
lcall delay
clr a
movx @dptr,a
ret
;键盘扫描子程序
keyscan:
mov a,#0
mov dptr,#4f02
movx @dptr,a
lcall testkey
jnz kn1
sjmp fret
kn1:
lcall getkey
mov r7,a
lcall aga
cjne r2,#0FFH,fret
lcall delay
lcall getkey
xrl a,r7
jnz fret
wait:
call testkey
jnz wait
mov a,r7
ret
fret:
mov a,#0FFH
ret
;测试是否有键按下
testkey:
mov dptr,#4f01
clr a
movx @dptr,a
mov dptr,#4f03
movx a,@dptr
cpl a
anl a,#0fh
ret
;延时
delay:
mov r0,#0
djnz r0,$
ret
;取得按下键的键值
getkey:
mov r5,#8
mov r3,#0FEH
lop1:
mov dptr,#4f01H
mov a,r3
movx @dptr,a
;mov b,a
rl a
mov r3,a
mov dptr,#4F03H
movx a,@dptr
anl a,#0fh
cjne a,#0fh,nex1
aga:
djnz r5,lop1
mov r2,#0ffh
ret
nex1:
mov r1,a
mov a,#9
subb a,r5
rl a
rl a
mov r2,a
mov a,r1
mov r1,#4
cpl a
lop2:
rrc a
jc exit
inc r2
djnz r1,lop2
exit:
mov a,r2
mov dptr,#keytable
movc a,@a+dptr
ret
;键值表
keytable:
DB 00H,04H,08H,0CH
DB 10H,14H,18H,1CH
DB 01H,05H,09H,0DH
DB 11H,15H,19H,1DH
DB 02H,06H,0AH,0EH
DB 12H,16H,1AH,1EH
DB 03H,07H,0BH,0FH
DB 13H,17H,1BH,1FH
;8段码表
tab:
上一篇:51定时器实现频率检测
下一篇:基于单片机的高精度智能交直流电压数据采集系统设计
推荐阅读最新更新时间:2024-03-16 13:54