|
; p=pic16c71,xt=40000hz
LIST P=16c71
;
Z EQU 2
RBPU EQU 7
TEMP EQU 10H
OPTIONREG EQU 1H
F EQU 1
PORT_B EQU 06H
;
INCLUDE <P16c71.INC>
LIST
;
ORG 0 ;复位地址
GOTO START
;
ORG 4 ;中断向量
GOTO SERVICEINTERRUPT
;
START
CALL INITPORT_B ;初始化B口
LOOP
SLEEP ;省电睡眠,等待被唤醒
NOP
GOTO LOOP
;
SERVICEINTERRUPT
BTFSC INTCON,RBIF
GOTO SERVICEWAKUP
CLRF INTCON
BSF INTCON,RBIE
RETFIE
;
;检查是哪个键被按下,并点亮相应的LED直到按键释放,再返回睡眠状态
;
SERVICEWAKUP
BCF INTCON,RBIE
COMF PORT_B,W
BCF INTCON,RBIF
CALL DELAY16
COMF PORT_B,W
ANDLW B'11110000'
MOVWF TEMP
SWAPF TEMP,W
MOVWF PORT_B
CALL KEYRELEASE
RETFIE
;
;等待所有的按键都被释放程序
;
KEYRELEASE
CALL DELAY16
COMF PORT_B,W
BCF INTCON,RBIF
BCF INTCON,RBIE
ANDLW B'11110000'
BTFSC STATUS,Z
RETURN
GOTO KEYRELEASE
;
;初始化 B口子程序
;
INITPORT_B
BSF STATUS,RP0
MOVLW B'11110000'
MOVWF TRISB
BCF OPTIONREG,RBPU
BCF STATUS,RP0
CLRF PORT_B
BCF INTCON,RBIE
MOVF PORT_B,W
BCF INTCON,RBIF
BSF INTCON,RBIE
BSF INTCON,GIE
RETURN
;
;延时去抖动子程序
DELAY16
BSF STATUS,RP0
MOVLW B'00000111'
MOVWF OPTIONREG
BCF STATUS,RP0
CLRF TMR0
BCF INTCON,T0IF
CHECKAGAIN
BTFSS INTCON,T0IF
GOTO CHECKAGAIN
BCF INTCON,T0IF
RETURN
END |
|