c51版键盘扫描·
Author:100
org 00h
ajmp main
main:
mov p2,#01h ;开启第一个led显示
mov r0,#01h
mov r2,#00h ;保存行数
mov r3,#00h ;保存列数
mov dptr,#para
mov p1,#0f0h ;初始化p1,先判断行 ;开中断
first:
jnb p1.4,h1
jnb p1.5,h2
jnb p1.6,h3
jnb p1.7,h4
inc r0
djnz r0,first
h1:
mov r2,#00h
mov p1,#0fh
ajmp second
h2:
mov r2,#01h
mov p1,#0fh
ajmp second
h3:
mov r2,#02h
mov p1,#0fh
ajmp second
h4:
mov r2,#03h
mov p1,#0fh
ajmp second
second:
jnb p1.0,l1
jnb p1.1,l2
jnb p1.2,l3
jnb p1.3,l4
l1:
mov r3,#01h
ajmp count
l2:
mov r3,#02h
ajmp count
l3:
mov r3,#03h
ajmp count
l4:
mov r3,#04h
ajmp count
count:
mov b,#04h
mov a,r2
mul ab
add a,r3
mov r4,a
loop:
inc dptr
djnz r4,loop
mov a,#00h
movc a,@a+dptr
mov p0,a
mov r2,#00h
mov r3,#00h
mov dptr,#para
ajmp main
para:
db 3fh,06h,5bh,4fh,66h,6dh,7dh,07h,7fh,6fh,77h,7ch,39h,5eh,79h,71h,73h
end