英锐恩单片机论坛,Microchip单片机,模拟器件,接口电路,麦肯单片机,单片机应用交流
标题:
PIC16C71单片机按键换醒CPU源程序
[打印本页]
作者:
winnie
时间:
2009-5-5 17:27
标题:
PIC16C71单片机按键换醒CPU源程序
; 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
欢迎光临 英锐恩单片机论坛,Microchip单片机,模拟器件,接口电路,麦肯单片机,单片机应用交流 (http://enroobbs.com/)
Powered by Discuz! X3.2