PIC單片機(jī)的4*4鍵盤子程序
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
;-------------------------------
; 測(cè)試程序(注意用法,鍵值放在JIANZHI里)
;-------------------------------
MAIN
MOVLW 0
TRIS RC
CLRF RC
MOVLW B'00001111' ;用RB口作4*4鍵盤
TRIS RB
LOOP CLRF RC
CALL SCANKEY
ANDLW 0FH
SKPNZ ;根據(jù)返回值不為零,判斷有無(wú)鍵按下
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
本文引用地址:http://2s4d.com/article/172845.htm
評(píng)論