按键低功耗,按键唤醒
1.设置按键为键盘唤醒,按键为低,触发按键中断,唤醒MCU
void KbAppInit(void)
{
SET_COL_ALL_IN; //列输入
SET_ROW_ALL_OUT1; //行输出高电平
RemoteGroup=0;
RollingCode=0;
ResetUserTimer(&KeyUpTimer); //更新按键抬起时间
ResetUserTimer(&KeyDownTimer);
ResetUserTimer(&EnterSleepTimer);
KeyDown=0;
KeyReleaseSendEn=0;
UpdataKeyReleaseSendBufEn=0;
KeyDownNoSendEn=0;
UpdataKeyDownStepEn=1;
}
2.MCU唤醒后执行主程序,在键盘唤醒中不做处理。当检测到某个引脚满足中断条件,并且该引脚的在键盘控制寄存器KBCON中被允许,则设置键盘中断标志位KBF。当按键释放时KBF被自动清0.任何一个被允许的键盘中断都可以将器件从空闲、停止或睡眠模式中唤醒
3.按键松开后重新进入休眠状态
void EnterSleep(void)
{
uint8_t IE0Data;
uint8_t IE1Data;
IE0Data=IE0;
IE1Data=IE1;
SET_COL_ALL_IN; //设列为输入
SET_ROW_ALL_OUT0; //设行为输出0
SET_ROW0_OUT0;
KbScanWaitIOConfigSteady();
if((COL1==0) || (COL2==0)||(COL3==0)||(COL4==0))
{
return;
}
//LED_OFF;
TCON=0; //关闭定时器
WdtDis(); //关闭看门狗
PSFT |= 0x18; //int0b,int1b移位控制
PSFT1|=0x08; //键盘接口移位控制
KBCON=(BIT0|BIT1); //设置kb1,kb0中断有效
TCON &= ~(BIT0|BIT2); //int0b,int1b 低电平触发
IE0=0x85; //允许外部中断int0b,int1b
IE1=0x10; //允许键盘中断
if(((IRCON&0x10)==0)&&((TCON&0x08) == 0)&&((TCON&0x02)== 0)) //键盘中断标志位为0,外部中断0,1为0
{
Sleep();
}
PSFT &= ~0x18; //清除int0b,int1b移位标志
PSFT1&=~0x08; //清除键盘接口移位标志
KBCON=0; //清除键盘中断控制位
IE0=IE0Data;
IE1=IE1Data;
WdtInit(WDT_2S_INT);
SysTickInit();
PrfAppInit();
PrfSleep();
ResetUserTimer(&KeyUpTimer); //更新按键松开时间KeyUpTimer
ResetUserTimer(&KeyDownTimer); //更新按键按下时间KeyDownTimer
ResetUserTimer(&EnterSleepTimer); //更新睡眠时间EnterSleepTimer
}