PIC16C71單片機(jī)按鍵換醒CPU源程序
LISTP=16c71
;
ZEQU2
RBPUEQU7
TEMPEQU10H
OPTIONREGEQU1H
FEQU1
PORT_BEQU06H
;
INCLUDEP16c71.INC>
LIST
;
ORG0;復(fù)位地址
GOTOSTART
;
ORG4;中斷向量
GOTOSERVICEINTERRUPT
;
START
CALLINITPORT_B;初始化B口
LOOP
SLEEP;省電睡眠,等待被喚醒
NOP
GOTOLOOP
;
SERVICEINTERRUPT
BTFSCINTCON,RBIF
GOTOSERVICEWAKUP
CLRFINTCON
BSFINTCON,RBIE
RETFIE
;
;檢查是哪個(gè)鍵被按下,并點(diǎn)亮相應(yīng)的LED直到按鍵釋放,再返回睡眠狀態(tài)
;
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
;
;延時(shí)去抖動(dòng)子程序
DELAY16
BSFSTATUS,RP0
MOVLWB'00000111'
MOVWFOPTIONREG
BCFSTATUS,RP0
CLRFTMR0
BCFINTCON,T0IF
CHECKAGAIN
BTFSSINTCON,T0IF
GOTOCHECKAGAIN
BCFINTCON,T0IF
RETURN
END
評(píng)論