控制工程师论坛

人机界面

汇编键盘扫描程序

norka
norka

2007-11-29

我的键盘扫描程序:



key equ p2
disp equ p0



;7------+--+--+--+
;6------+--+--+--+
;5------+--+--+--+
;4------+--+--+--+
;3______|  |  |  |
;2_________|  |  |
;1____________|  |
;0_______________|


      
       org 0000h
       ajmp start
       org 0100h
start: mov disp,#0
       mov dptr,#tab
loopscan:acall keyin
       acall keyoff
       mov a,r0
       movc a,@a+dptr
       mov disp,a
       ajmp loopscan
      


 


keyin:  mov key,#0fh
        mov a,key
        cjne a,#0fh,select
        sjmp keyin
select: mov a,key  
        cjne a,#0eh,next1
        ajmp row1
next1:  cjne a,#0dh,next2
        ajmp row2
next2:  cjne a,#0bh,next3
        ajmp row3
next3:  ajmp row4


row1:   mov key,#0feh
        mov a,key
        cjne a,#0feh,row1scan
        ajmp row2
row1scan:cjne a,#0eeh,row11
         mov r0,#12
         acall delay20ms
         ajmp scanend
row11:   cjne a,#0deh,row12
         mov r0,#13
         acall delay20ms
         ajmp scanend       
row12:   cjne a,#0beh,row13
         mov r0,#14
         acall delay20ms
         ajmp scanend
row13:   mov r0,#15
         acall delay20ms
         ajmp scanend
        



row2:   mov key,#0fdh
        mov a,key
        cjne a,#0fdh,row2scan
        ajmp row3
row2scan:cjne a,#0edh,row21
         acall delay20ms
         mov r0,#8
         ajmp scanend
row21:   cjne a,#0ddh,row22
         mov r0,#9
         acall delay20ms
         ajmp scanend       
row22:   cjne a,#0bdh,row23
         mov r0,#10
         acall delay20ms
         ajmp scanend
row23:   mov r0,#11
         acall delay20ms
         ajmp scanend


row3:   mov key,#0fbh
        mov a,key
        cjne a,#0fbh,row3scan
        ajmp row4
row3scan:cjne a,#0ebh,row31
         mov r0,#4
         acall delay20ms
         ajmp scanend
row31:   cjne a,#0dbh,row32
         mov r0,#5
         acall delay20ms
         ajmp scanend       
row32:   cjne a,#0bbh,row33
         mov r0,#6
         acall delay20ms
         ajmp scanend
row33:   mov r0,#7
         acall delay20ms
         ajmp scanend


row4:    mov key,#0f7h
         mov a,key
         cjne a,#0e7h,row41
         mov r0,#0
         acall delay20ms
         ajmp scanend
row41:   cjne a,#0d7h,row42
         mov r0,#1
         acall delay20ms
         ajmp scanend       
row42:   cjne a,#0b7h,row43
         mov r0,#2
         acall delay20ms
         ajmp scanend
row43:   mov r0,#3
         acall delay20ms
         ajmp scanend


scanend:ret



;判断是否松开
keyoff:  mov key,#0fh
         mov a,key
         cjne a,#0fh,keyret
         sjmp keyoff
keyret:  acall delay20ms
         ret
;!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
;!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
;12Mhz Crystal!!!!!!!!!!!!!!!!!!!!!!!12周期单片机
delay20ms:mov r7,#250
delay20msd0:mov r6,#60
delay20msd1:djnz r6,$
            djnz r7,delay20msd0
            ret
           
tab:db 11100111b,10000100b,11010011b,11010110b,10110100b,01110110b,01110111b,11000100b,11110111b,11110110b


db 11110101b,00110111b,01100011b,10010111b,01110011b,01110001b,01100111b,10110101b,00100001b,10000111b
db 00100011b,00010101b,00010111b,11110001b,11110100b,10110110b


         end

回帖

评论0

首页 | 登录 | 注册 | 返回顶部↑
手机版 | 电脑版
版权所有 Copyright(C) 2016 CE China