#include "wkup.h"
|
#include "delay.h"
|
//////////////////////////////////////////////////////////////////////////////////
|
//±¾³ÌÐòÖ»¹©Ñ§Ï°Ê¹Óã¬Î´¾×÷ÕßÐí¿É£¬²»µÃÓÃÓÚÆäËüÈκÎÓÃ;
|
//ALIENTEKÕ½½¢STM32¿ª·¢°å
|
//´ý»ú»½ÐÑ ´úÂë
|
//ÕýµãÔ×Ó@ALIENTEK
|
//¼¼ÊõÂÛ̳:www.openedv.com
|
//ÐÞ¸ÄÈÕÆÚ:2012/9/7
|
//°æ±¾£ºV1.0
|
//°æÈ¨ËùÓУ¬µÁ°æ±Ø¾¿¡£
|
//Copyright(C) ¹ãÖÝÊÐÐÇÒíµç×ӿƼ¼ÓÐÏÞ¹«Ë¾ 2009-2019
|
//All rights reserved
|
//////////////////////////////////////////////////////////////////////////////////
|
|
void Sys_Standby(void)
|
{
|
RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE); //ʹÄÜPWRÍâÉèʱÖÓ
|
PWR_WakeUpPinCmd(ENABLE); //ʹÄÜ»½ÐѹܽʦÄÜ
|
PWR_EnterSTANDBYMode(); //½øÈë´ýÃü£¨STANDBY£©Ä£Ê½
|
}
|
//ϵͳ½øÈë´ý»úģʽ
|
void Sys_Enter_Standby(void)
|
{
|
RCC_APB2PeriphResetCmd(0X01FC,DISABLE); //¸´Î»ËùÓÐIO¿Ú
|
Sys_Standby();
|
}
|
// //¼ì²âWKUP½ÅµÄÐźÅ
|
// //·µ»ØÖµ1:PA0Ϊ¸ßµçƽ
|
// // 0:PA0ΪµÍµçƽ
|
u8 Check_WKUP(void)
|
{
|
|
if(WKUP_KD == 0)
|
{
|
delay_ms(250);
|
if(WKUP_KD == 0)
|
{
|
return 0;
|
}
|
}
|
|
if(WKUP_KD == 1)
|
{
|
delay_ms(250);
|
if(WKUP_KD == 1)
|
{
|
return 1;
|
}
|
}
|
}
|
|
//ÖжÏ,¼ì²âµ½PA0½ÅµÄÒ»¸öÉÏÉýÑØ.
|
//ÖжÏÏß0ÏßÉϵÄÖжϼì²â
|
|
|
void EXTI0_IRQHandler(void)
|
{
|
EXTI_ClearITPendingBit(EXTI_Line0); // Çå³ýLINE10ÉϵÄÖжϱê־λ
|
if(Check_WKUP())//¹Ø»ú?
|
{
|
Sys_Enter_Standby();
|
}
|
}
|
//PA0 WKUP»½Ðѳõʼ»¯
|
void WKUP_Init(void)
|
{
|
GPIO_InitTypeDef GPIO_InitStructure;
|
NVIC_InitTypeDef NVIC_InitStructure;
|
EXTI_InitTypeDef EXTI_InitStructure;
|
|
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_AFIO, ENABLE);//ʹÄÜGPIOAºÍ¸´Óù¦ÄÜʱÖÓ
|
|
GPIO_InitStructure.GPIO_Pin =GPIO_Pin_0; //PA.0
|
GPIO_InitStructure.GPIO_Mode =GPIO_Mode_IPD;//ÉÏÀÊäÈë
|
GPIO_Init(GPIOA, &GPIO_InitStructure); //³õʼ»¯IO
|
//ʹÓÃÍⲿÖжϷ½Ê½
|
GPIO_EXTILineConfig(GPIO_PortSourceGPIOA, GPIO_PinSource0); //ÖжÏÏß0Á¬½ÓGPIOA.0
|
|
EXTI_InitStructure.EXTI_Line = EXTI_Line0; //ÉèÖð´¼üËùÓеÄÍⲿÏß·
|
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt; //ÉèÍâÍⲿÖжÏģʽ:EXTIÏß·ΪÖжÏÇëÇó
|
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 = 2; //ÏÈÕ¼ÓÅÏȼ¶2¼¶
|
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 2; //´ÓÓÅÏȼ¶2¼¶
|
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //ʹÄÜÍⲿÖжÏͨµÀ
|
NVIC_Init(&NVIC_InitStructure); //¸ù¾ÝNVIC_InitStructÖÐÖ¸¶¨µÄ²ÎÊý³õʼ»¯ÍâÉèNVIC¼Ä´æÆ÷
|
|
if(Check_WKUP()==0) Sys_Standby(); //²»ÊÇ¿ª»ú,½øÈë´ý»úģʽ
|
}
|
///////////////////////////////////////////
|
//RTC¶¨Ê±»½ÐÑ
|
void EXTI_Configuration(void)
|
{
|
EXTI_InitTypeDef EXTI_InitStructure;
|
|
/* Configure EXTI Line17(RTC Alarm) to generate an interrupt on rising edge */
|
EXTI_ClearITPendingBit(EXTI_Line17);
|
EXTI_InitStructure.EXTI_Line = EXTI_Line17;
|
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
|
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising;
|
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
|
EXTI_Init(&EXTI_InitStructure);
|
|
}
|
|
void RTCAlarm_IRQHandler(void)
|
{
|
EXTI->PR=1<<17; //Çå³ýLINE17ÉϵÄÖжϱê־λ
|
SystemInit();
|
}
|
|
void RTC_Configuration(void)
|
{
|
RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR | RCC_APB1Periph_BKP, ENABLE);
|
PWR_BackupAccessCmd(ENABLE);
|
if(PWR_GetFlagStatus(PWR_FLAG_SB) != RESET)
|
{
|
PWR_ClearFlag(PWR_FLAG_SB);
|
RTC_WaitForSynchro();
|
}
|
else
|
{
|
BKP_DeInit();
|
RCC_LSEConfig(RCC_LSE_ON);
|
// RCC_LSICmd(ENABLE);
|
while(RCC_GetFlagStatus(RCC_FLAG_LSERDY) == RESET)
|
{
|
}
|
/* Ñ¡Ôñ LSE Ϊ RTC ʱÖÓÔ´ */
|
RCC_RTCCLKConfig(RCC_RTCCLKSource_LSE);
|
|
// RCC_RTCCLKConfig(RCC_RTCCLKSource_LSI);
|
RCC_RTCCLKCmd(ENABLE);
|
RTC_WaitForSynchro();
|
// RTC_SetPrescaler(39999);
|
RTC_SetPrescaler(32767);
|
|
RTC_WaitForLastTask();
|
}
|
RTC_ITConfig(RTC_IT_ALR, ENABLE);
|
RTC_WaitForLastTask();
|
RTC_SetAlarm(RTC_GetCounter()+ 5);
|
RTC_WaitForLastTask();
|
}
|
|
// void NVIC_Configuration(void)
|
// {
|
// NVIC_InitTypeDef NVIC_InitStructure;
|
// NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
|
|
// NVIC_InitStructure.NVIC_IRQChannel = RTCAlarm_IRQn;
|
// NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
|
// NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
|
// NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
|
// NVIC_Init(&NVIC_InitStructure);
|
|
// }
|