就是按照原子哥的待机唤醒程序
现在是上电进入待机了
按键3s进入正常模式,然后再按键会迅速复位进入正常模式,不知道什么原因
void Wkup_Init(void)
{
EXTI_InitTypeDef EXTI_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
GPIO_InitTypeDef GPIO_InitStruct;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO|RCC_APB2Periph_GPIOA,ENABLE);
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_IPD;
GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStruct.GPIO_Pin = KEY0_PIN;
GPIO_Init(KEY0,&GPIO_InitStruct);
GPIO_EXTILineConfig(GPIO_PortSourceGPIOA,GPIO_PinSource0);
EXTI_InitStructure.EXTI_Line = EXTI_Line0; //PA0
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising;
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
EXTI_Init(&EXTI_InitStructure);
NVIC_InitStructure.NVIC_IRQChannel = EXTI0_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
void EXTI0_IRQHandler(void)
{
EXTI_ClearITPendingBit(EXTI_Line0);
if(Check_up())
{
Sys_Enter_Standby();
}
}
void Sys_Standby(void) //
{
RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE);
PWR_WakeUpPinCmd(ENABLE);
PWR_EnterSTANDBYMode();
}
void Sys_Enter_Standby(void)//
{
RCC_APB2PeriphResetCmd(0X01FC,DISABLE); //
Sys_Standby();
}
u8 Check_up(void)
{
u8 t = 0;
u8 tx = 0;
while(1)
{
if( GPIO_ReadInputDataBit(KEY0,KEY0_PIN)== 1) //
{
t++;
tx = 0;
}
else
{
tx++;
if(tx > 3)
{
return 0; //????????????
}
}
delay_ms(30);
if(t > 100) //100*30ms = 3s
{
return 1;// 3s
}
}
}
int main(void)
{
u8 i;
Clock_Init();
NVIC_Configuration();// nvic 分组4
delay_init();
LED_Init();
Wkup_Init();
if(Check_up() == 0) //
{ Sys_Standby(); }
while(1);
}
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
一周热门 更多>