📄 key12.inc
字号:
;
;----------------------------------------------------------
; KEY12.INC MPB 15-1-06
; Routine to scan 3x4 phone key pad
; Returns ASCII code in W
;----------------------------------------------------------
Cont EQU 30 ; Delay counter
Key EQU 31 ; Input key
Test EQU 32 ; Key check
; Initialise registers ------------------------------------
key12 NOP ; Setup port
BANKSEL TRISC ; bidirectional
MOVLW B'00001111' ;
MOVWF TRISC ; for keypad
BANKSEL PORTC ; back to data reg
MOVLW 0FF ; Initialise...
MOVWF PORTC ; Keypad rows high
MOVWF Cont ; Counter not zero
BSF PORTD,0
CLRF Test ; No key
; Scan keyboard -------------------------------------------
again CLRW ; No key
BCF PORTC,5 ; Row 1
NOP ; wait
NOP
BTFSS PORTC,0 ; key pressed?
MOVLW '1' ; yes - load ASCII code
BTFSS PORTC,1 ; next
MOVLW '2' ; etc
BTFSS PORTC,2 ;
MOVLW '3' ;
BSF PORTC,5 ; deselect row
; ---------------------------------------------------------
BCF PORTC,6 ; second row
BTFSS PORTC,0
MOVLW '4'
BTFSS PORTC,1
MOVLW '5'
BTFSS PORTC,2
MOVLW '6'
BSF PORTC,6
; ---------------------------------------------------------
BCF PORTC,7 ; third row
BTFSS PORTC,0
MOVLW '7'
BTFSS PORTC,1
MOVLW '8'
BTFSS PORTC,2
MOVLW '9'
BSF PORTC,7
; ---------------------------------------------------------
BCF PORTD,0 ; fourth row
BTFSS PORTC,0
MOVLW '*'
BTFSS PORTC,1
MOVLW '0'
BTFSS PORTC,2
MOVLW '#'
BSF PORTD,0
;Test key -------------------------------------------------
MOVWF Test ; get code
MOVF Test,F ; test it
BTFSS STATUS,Z ; if code found
GOTO once ; beep once
MOVF Key,W
RETURN ; if no key, or released
; Check if beep done --------------------------------------
once MOVF Cont,F ; beep already done?
BTFSC STATUS,Z ;
GOTO again ; yes - scan again
MOVF Test,W ; store key
MOVWF Key
; Beep ----------------------------------------------------
beep MOVLW 10 ; 10 cycles
MOVWF Cont
buzz BSF PORTB,0 ; one beep cycle
CALL onems ; 2ms
BCF PORTB,0
CALL onems
DECFSZ Cont ; last cycle?
GOTO buzz ; no
GOTO again ; yes
; ---------------------------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -