金沙js5线路(中国)有限公司

技术热线: 4007-888-234

PIC单片机的4*4键盘子程序

更新时间: 2019-03-22
阅读量:2557

单片机开发商深圳金沙js5线路分享PIC单片机的4*4键盘子程序。

;-------4*4键盘程序的使用--------
PC       EQU    2
STATUS   EQU    3
RA       EQU    5
RB       EQU    6
RC       EQU    7
BIJIAO   EQU    0F
JIANZHI  EQU    8
BUFFER   EQU    9
BUFFER1  EQU    0AH
BUFFER2  EQU    0BH
COUNTER  EQU    0CH
CON1     EQU    0DH
CON2     EQU    0EH
PIC57    EQU    7FFH
Z        EQU    2
;-----------------------------
         ORG    PIC57
         GOTO   MAIN
;-----------------------------
         ORG    0
;-----------------------------

 延时子程序
;----------------------------
DELAY    MOVLW  D'100'
         MOVWF  CON1
L1       MOVLW  D'200'
         MOVWF  CON2
L2       DECFSZ CON2,1
         GOTO   L2
         DECFSZ CON1,1
         GOTO   L1
         RETLW  0        
;-----------------------------
;        4*4键盘扫描判断子程序
;-----------------------------
SCANKEY
         MOVLW  B'11101111'
         MOVWF  RB
         MOVF   RB,W
         ANDLW  B'00001111'
         MOVWF  BUFFER
         MOVLW  B'00001111'

  XORWF  BUFFER,W
         SKPNZ
         GOTO   XYB1
         MOVWF  BUFFER1
         MOVLW  1
         MOVWF  JIANZHI
         MOVF   RB,W
         MOVWF  BIJIAO
         GOTO   QJZ

XYB1     MOVLW  B'11011111'
         MOVWF  RB
         MOVF   RB,W
         ANDLW  B'00001111'
         MOVWF  BUFFER
         MOVLW  B'00001111'
         XORWF  BUFFER,W
         SKPNZ
         GOTO   XYB2
         MOVWF  BUFFER1
         MOVLW  5
         MOVWF  JIANZHI
         GOTO   QJZ

XYB2     MOVLW  B'10111111'
         MOVWF  RB
         MOVF   RB,W
         ANDLW  B'00001111'
         MOVWF  BUFFER
         MOVLW  B'00001111'
         XORWF  BUFFER,W
         SKPNZ
         GOTO   XYB3
         MOVWF  BUFFER1
         MOVLW  9
         MOVWF  JIANZHI
         MOVF   RB,W
         MOVWF  BIJIAO
         GOTO   QJZ

XYB3     MOVLW  B'01111111'
         MOVWF  RB
         MOVF   RB,W
         ANDLW  B'00001111'

  MOVWF  BUFFER
         MOVLW  B'00001111'
         XORWF  BUFFER,W
         SKPNZ
         RETLW  0
         MOVWF  BUFFER1
         MOVLW  0DH
         MOVWF  JIANZHI
         MOVF   RB,W
         MOVWF  BIJIAO

QJZ      MOVLW  1
         MOVWF  BUFFER2
         MOVLW  4
         MOVWF  COUNTER

QJZ1     MOVF   BUFFER1,W
         SUBWF  BUFFER2,W

SKPNZ
         RETLW  1
         RLF    BUFFER2,1
         INCF   JIANZHI,1
         DECFSZ COUNTER,1
         GOTO   QJZ1
         RETLW  0
;-------------------------------
;    测试程序(注意用法,键值放在JIANZHI里)
;-------------------------------
MAIN
         MOVLW  0
         TRIS   RC
         CLRF   RC
         MOVLW  B'00001111'     ;用RB口作4*4键盘
         TRIS   RB
LOOP     CLRF   RC
         CALL   SCANKEY
         ANDLW  0FH
         SKPNZ                  ;根据返回值不为零,判断有无键按下

GOTO   LOOP
         MOVLW  0FH
         ANDWF  JIANZHI,W
         MOVWF  RC
         CALL   DELAY

LOOP1    MOVF   BUFFER1,W
         ANDWF  RB,W
         XORWF  BIJIAO,W
         SKPNZ
         GOTO   LOOP1
         GOTO   LOOP
;--------------
;-------------------------------
         END

XML 地图