;p=pic16c71,xt=40000hz
LISTP=16c71
;
ZEQU2
RBPUEQU7
TEMPEQU10H
OPTIONREGEQU1H
FEQU1
PORT_BEQU06H
;
INCLUDE<P16c71.INC>
LIST
;
ORG0;复位地址
GOTOSTART
;
ORG4;中断向量
GOTOSERVICEINTERRUPT
;
START
CALLINITPORT_B;初始化B口
LOOP
SLEEP;省电睡眠,等待被唤醒
NOP
GOTOLOOP
;
SERVICEINTERRUPT
BTFSCINTCON,RBIF
GOTOSERVICEWAKUP
CLRFINTCON
BSFINTCON,RBIE
RETFIE
;
;检查是哪个键被按下,并点亮相应的LED直到按键释放,再返回睡眠状态
;
SERVICEWAKUP
BCFINTCON,RBIE
COMFPORT_B,W
BCFINTCON,RBIF
CALLDELAY16
COMFPORT_B,W
ANDLWB'11110000'
MOVWFTEMP
SWAPFTEMP,W
MOVWFPORT_B
CALLKEYRELEASE
RETFIE
;
;等待所有的按键都被释放程序
;
KEYRELEASE
CALLDELAY16
COMFPORT_B,W
BCFINTCON,RBIF
BCFINTCON,RBIE
ANDLWB'11110000'
BTFSCSTATUS,Z
RETURN
GOTOKEYRELEASE
;
;初始化B口子程序
;
INITPORT_B
BSFSTATUS,RP0
MOVLWB'11110000'
MOVWFTRISB
BCFOPTIONREG,RBPU
BCFSTATUS,RP0
CLRFPORT_B
BCFINTCON,RBIE
MOVFPORT_B,W
BCFINTCON,RBIF
BSFINTCON,RBIE
BSFINTCON,GIE
RETURN
;
;延时去抖动子程序
DELAY16
BSFSTATUS,RP0
MOVLWB'00000111'
MOVWFOPTIONREG
BCFSTATUS,RP0
CLRFTMR0
BCFINTCON,T0IF
CHECKAGAIN
BTFSSINTCON,T0IF
GOTOCHECKAGAIN
BCFINTCON,T0IF
RETURN
END