PIC单片机的4*4键盘子程序
<!--StartFragment-->;-------4*4键盘程序的使用--------PC EQU 2
STATUS EQU 3
RA EQU 5
RB EQU 6
RC EQU 7
BIJIAO EQU 0F
JIANZHIEQU 8
BUFFER EQU 9
BUFFER1EQU 0AH
BUFFER2EQU 0BH
COUNTEREQU 0CH
CON1 EQU 0DH
CON2 EQU 0EH
PIC57 EQU 7FFH
Z EQU 2
;-----------------------------
ORG PIC57
GOTO MAIN
;-----------------------------
ORG 0
;-----------------------------
; 延时子程序
;----------------------------
DELAY MOVLWD'100'
MOVWFCON1
L1 MOVLWD'200'
MOVWFCON2
L2 DECFSZ CON2,1
GOTO L2
DECFSZ CON1,1
GOTO L1
RETLW0
;-----------------------------
; 4*4键盘扫描判断子程序
;-----------------------------
SCANKEY
MOVLWB'11101111'
MOVWFRB
MOVF RB,W
ANDLWB'00001111'
MOVWFBUFFER
MOVLWB'00001111'
XORWFBUFFER,W
SKPNZ
GOTO XYB1
MOVWFBUFFER1
MOVLW1
MOVWFJIANZHI
MOVF RB,W
MOVWFBIJIAO
GOTO QJZ
XYB1 MOVLWB'11011111'
MOVWFRB
MOVF RB,W
ANDLWB'00001111'
MOVWFBUFFER
MOVLWB'00001111'
XORWFBUFFER,W
SKPNZ
GOTO XYB2
MOVWFBUFFER1
MOVLW5
MOVWFJIANZHI
GOTO QJZ
XYB2 MOVLWB'10111111'
MOVWFRB
MOVF RB,W
ANDLWB'00001111'
MOVWFBUFFER
MOVLWB'00001111'
XORWFBUFFER,W
SKPNZ
GOTO XYB3
MOVWFBUFFER1
MOVLW9
MOVWFJIANZHI
MOVF RB,W
MOVWFBIJIAO
GOTO QJZ
XYB3 MOVLWB'01111111'
MOVWFRB
MOVF RB,W
ANDLWB'00001111'
MOVWFBUFFER
MOVLWB'00001111'
XORWFBUFFER,W
SKPNZ
RETLW0
MOVWFBUFFER1
MOVLW0DH
MOVWFJIANZHI
MOVF RB,W
MOVWFBIJIAO
QJZ MOVLW1
MOVWFBUFFER2
MOVLW4
MOVWFCOUNTER
QJZ1 MOVF BUFFER1,W
SUBWFBUFFER2,W
SKPNZ
RETLW1
RLF BUFFER2,1
INCF JIANZHI,1
DECFSZ COUNTER,1
GOTO QJZ1
RETLW0
;-------------------------------
; 测试程序(注意用法,键值放在JIANZHI里)
;-------------------------------
MAIN
MOVLW0
TRIS RC
CLRF RC
MOVLWB'00001111' ;用RB口作4*4键盘
TRIS RB
LOOP CLRF RC
CALL SCANKEY
ANDLW0FH
SKPNZ ;根据返回值不为零,判断有无键按下
GOTO LOOP
MOVLW0FH
ANDWFJIANZHI,W
MOVWFRC
CALL DELAY
LOOP1 MOVF BUFFER1,W
ANDWFRB,W
XORWFBIJIAO,W
SKPNZ
GOTO LOOP1
GOTO LOOP
;--------------
;-------------------------------
END
页:
[1]