51/AVR单片机技术驿站!  <在线翻译>     便利工具    特色网址   无弹窗、无插件的绿色站点...  英才招聘   学历查询  喜欢>>收藏我站 

当前位置:首页 > 单片机源码 > 详细内容
各种各样的矩阵键盘扫描程序集
发布时间:2009/7/7  阅读次数:4585  字体大小: 【】 【】【

NOKEY2:  MOV   P3,#0FFH
           CLR   P3.4
           MOV   A,P1
           ANL   A,#0FH
           XRL   A,#0FH
           JZ   NOKEY3
           LCALL   DL10MS
           MOV   A,P1
           ANL   A,#0FH
           XRL   A,#0FH
           JZ   NOKEY3
           MOV   A,P1
           ANL   A,#0FH
           CJNE   A,#0EH,KB10
           MOV   KEYBUF,#8
           LJMP   KEYWORK
KB10:   CJNE   A,#0DH,KB11
           MOV   KEYBUF,#9
           LJMP   KEYWORK
KB11:   CJNE   A,#0BH,KB12
           MOV   KEYBUF,#10
           LJMP   KEYWORK
KB12:   CJNE   A,#07H,KB13
           MOV   KEYBUF,#11
           LJMP   KEYWORK
KB13:   NOP
  ;
NOKEY3:  MOV   P3,#0FFH
           CLR   P3.5
           MOV   A,P1
           ANL   A,#0FH
           XRL   A,#0FH
           JZ   NOKEY4
           LCALL   DL10MS
           MOV   A,P1
           ANL   A,#0FH
           XRL   A,#0FH
           JZ   NOKEY4
           MOV   A,P1
           ANL   A,#0FH
           CJNE   A,#0EH,KB14
           MOV   KEYBUF,#12
           LJMP   KEYWORK
KB14:   CJNE   A,#0DH,KB15
           MOV   KEYBUF,#13
           LJMP   KEYWORK
KB15:   CJNE   A,#0BH,KB16
           MOV   KEYBUF,#14
           LJMP   KEYWORK
KB16:   CJNE   A,#07H,KB17
           MOV   KEYBUF,#15
           LJMP   KEYWORK
KB17:   NOP
  ;
NOKEY4:  MOV   P3,#0FFH
           CLR   P3.7
           MOV   A,P1
           ANL   A,#0FH
           XRL   A,#0FH
           JZ   NOKEY5
           LCALL   DL10MS
           MOV   A,P1
           ANL   A,#0FH
           XRL   A,#0FH
           JZ   NOKEY5
           MOV   A,P1
           ANL   A,#0FH
           CJNE   A,#0EH,KB18
           MOV   KEYBUF,#16
           LJMP   KEYWORK
KB18:   CJNE   A,#0DH,KB19
           MOV   KEYBUF,#17
           LJMP   KEYWORK
KB19:   CJNE   A,#0BH,KB20
           MOV   KEYBUF,#18
           LJMP   KEYWORK
KB20:   CJNE   A,#07H,KB21
           MOV   KEYBUF,#19
           LJMP   KEYWORK
KB21:   NOP
  ;
NOKEY5:  LJMP   MAIN
  ;
KEYWORK:MOV   A,KEYBUF    ;得到键值
             MOV     DPTR,#TABLE
             MOVC   A,@A+DPTR    ;查行键值送ACC
             MOV   P0,A
  ;
WAITFREE:
           MOV   A,P1      ;以下程序等待键释放
           MOV   KEYBUF,#00H
           ANL   A,#0FH
           XRL   A,#0FH
           JNZ   WAITFREE
           RET
  ;
;*************************************
;*                                                                     *
;*                   延时513 us                           *
;*                                                                     *
;*************************************
  ;
;513微秒延时程序
DELAY:  MOV     R2,#0FEH
DELAY1:  DJNZ       R2,DELAY1
     RET
  ;
;*************************************
;*                                                                     *
;*                         延时10ms                         *
;*                                                                     *
;*************************************
  ;
;10毫秒延时程序
DL10MS:  MOV         R3,#14H
DL10MS1:LCALL     DELAY
               DJNZ       R3,DL10MS1
             RET
  ;
TABLE:                                                     ;七段显示器数据定义
  DB   0C0H, 0F9H, 0A4H, 0B0H, 99H ; 01234
           DB   92H,   82H,   0F8H, 80H,   90H ; 56789
           DB   88H,   83H,   0C6H,   0A1H, 86H; ABCDE
           DB   8EH                         ; F
  ;
           END                               ;程序结束

   KEYBUF EQU 30H
                       ORG 00H
START:           MOV KEYBUF,#2
WAIT:    
                       MOV P3,#0FFH
                       CLR P3.4
                       MOV A,P3
                       ANL A,#0FH  
                       XRL A,#0FH
                       JZ NOKEY1
                       LCALL DELY10MS
                       MOV A,P3
                       ANL A,#0FH
                       XRL A,#0FH
                       JZ NOKEY1
                       MOV A,P3
                       ANL A,#0FH
                       CJNE A,#0EH,NK1
                       MOV KEYBUF,#0
                       LJMP DK1
NK1:               CJNE A,#0DH,NK2
                       MOV KEYBUF,#1
                       LJMP DK1
NK2:               CJNE A,#0BH,NK3
                       MOV KEYBUF,#2
                       LJMP DK1
NK3:               CJNE A,#07H,NK4
                       MOV KEYBUF,#3
                       LJMP DK1
NK4:               NOP
DK1:      
                       MOV A,KEYBUF
                       MOV DPTR,#TABLE
                       MOVC A,@A+DPTR
                       MOV P0,A

DK1A:             MOV A,P3
                       ANL A,#0FH
                       XRL A,#0FH
                       JNZ DK1A
NOKEY1:
                       MOV P3,#0FFH
                       CLR P3.5
                       MOV A,P3
                       ANL A,#0FH
                       XRL A,#0FH
                       JZ NOKEY2
                       LCALL DELY10MS
                       MOV A,P3
                       ANL A,#0FH
                       XRL A,#0FH
                       JZ NOKEY2
                       MOV A,P3
                       ANL A,#0FH
                       CJNE A,#0EH,NK5
                       MOV KEYBUF,#4
                       LJMP DK2
NK5:               CJNE A,#0DH,NK6
                       MOV KEYBUF,#5
                       LJMP DK2
NK6:               CJNE A,#0BH,NK7
                       MOV KEYBUF,#6
                       LJMP DK2
NK7:               CJNE A,#07H,NK8
                       MOV KEYBUF,#7
                       LJMP DK2
NK8:               NOP
DK2:      
                       MOV A,KEYBUF
                       MOV DPTR,#TABLE
                       MOVC A,@A+DPTR
                       MOV P0,A

DK2A:             MOV A,P3
                       ANL A,#0FH
                       XRL A,#0FH
                       JNZ DK2A

我要评论
  • 匿名发表
  • [添加到收藏夹]
  • 发表评论:(匿名发表无需登录,已登录用户可直接发表。) 登录状态:未登录
最新评论
所有评论[0]
    暂无已审核评论!

网站导航 管理登陆 ┊ 免责声明 问题反馈  友链说明
本站部分内容来自网络共享资源,如有冒犯您的权利请来信告之删除或纠正!
不得对本站进行复制、盗链或镜像,转载内容须获得同意或授权;欢迎友情链接、站务合作!

    我要报警 Alexa
 mcusy_cn#126.com (请把#改成@) 交流:522422171
本站学习交流群:138..158(高级群1-)、77930286(高级群2)、61804809(群3)
Copyright© MCUSY All Rights Reserved
本站网警备案号: WZ36040002485
  ICP备案证书号:粤ICP备09034963号