#include "wkup.h"
#include "led.h"
#include "delay.h"
#include "usart.h"
//////////////////////////////////////////////////////////////////////////////////
//±¾3ìDòÖ»1©Ñ§Ï°ê1óã¬Î′¾-×÷ÕßDí¿é£¬2»μÃóÃóúÆäËüèÎoÎóÃí¾
//ALIENTEK STM32F407¿a·¢°å
//′y»ú»½DÑ ′úÂë
//ÕyμãÔ-×ó@ALIENTEK
//¼¼êõÂÛì3:
www.openedv.com
//′′½¨èÕÆú:2014/5/6
//°æ±¾£oV1.0
//°æè¨ËùóD£¬μá°æ±Ø¾¿¡£
//Copyright(C) 1ãÖYêDDÇòíμç×ó¿Æ¼¼óDÏT1«Ë¾ 2014-2024
//All rights reserved
//////////////////////////////////////////////////////////////////////////////////
//Ïμí3½øèë′y»úÄ£ê½
void Sys_Enter_Standby(void)
{
while(WKUP_KD); //μè′yWK_UP°′¼üËé¿a(ÔúóDRTCÖD¶Ïê±,±ØDëμèWK_UPËé¿aÔù½øèë′y»ú)
RCC_AHB1PeriphResetCmd(0X04FF,ENABLE);//¸′λËùóDIO¿ú
RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE);//ê1ÄüPWRê±Öó
PWR_BackupAccessCmd(ENABLE);//oó±¸Çøóò·ÃÎêê1Äü
//ÕaàïÎòÃǾíÖ±½ó1رÕÏà1ØRTCÖD¶Ï
RTC_ITConfig(RTC_IT_TS|RTC_IT_WUT|RTC_IT_ALRB|RTC_IT_ALRA,DISABLE);//1رÕRTCÏà1ØÖD¶Ï£¬¿éÄüÔúRTCêμÑé′ò¿aáË¡£
RTC_ClearITPendingBit(RTC_IT_TS|RTC_IT_WUT|RTC_IT_ALRB|RTC_IT_ALRA);//Çå3tRTCÏà1ØÖD¶Ï±ê־λ¡£
PWR_ClearFlag(PWR_FLAG_WU);//Çå3yWake-up ±êÖ¾
PWR_WakeUpPinCmd(ENABLE);//éèÖÃWKUPóÃóú»½DÑ
PWR_EnterSTANDBYMode(); //½øèë′y»úÄ£ê½
}
//¼ì2aWKUP½ÅμÄDÅoÅ
//·μ»ØÖμ1:á¬Dø°′ÏÂ3sòÔéÏ
// 0:′íÎóμÄ′¥·¢
u8 Check_WKUP(void)
{
u8 t=0;
u8 tx=0;//¼Ç¼Ëé¿aμÄ′Îêy
LED0=0; //ááμÆDS0
while(1)
{
if(WKUP_KD)//òѾ-°′ÏÂáË
{
t++;
tx=0;
}else
{
tx++;
if(tx>3)//3¬1y90msÄúûóDWKUPDÅoÅ
{
LED0=1;
return 0;//′íÎóμÄ°′¼ü,°′ÏÂ′Îêy2»1»
}
}
delay_ms(30);
if(t>=100)//°′ÏÂ3¬1y3ÃëÖó
{
LED0=0; //μãááDS0
return 1; //°′ÏÂ3sòÔéÏáË
}
}
}
//ÖD¶Ï,¼ì2aμ½
A0½ÅμÄò»¸öéÏéyÑØ.
//ÖD¶ÏÏß0ÏßéÏμÄÖD¶Ï¼ì2a
void EXTI0_IRQHandler(void)
{
EXTI_ClearITPendingBit(EXTI_Line0); // Çå3yLINE10éÏμÄÖD¶Ï±ê־λ
if(Check_WKUP())//1Ø»ú?
{
Sys_Enter_Standby(); //½øèë′y»úÄ£ê½
}
}
//PA0 WKUP»½DÑ3õê¼»ˉ
void WKUP_Init(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
EXTI_InitTypeDef EXTI_InitStructure;
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);//ê1ÄüGPIOAê±Öó
RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);//ê1ÄüSYSCFGê±Öó
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0; //PA0
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;//êäèëÄ£ê½
GPIO_InitStructure.GPIO_OType = GPIO_OType_OD;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_DOWN;//ÏÂà-
GPIO_Init(GPIOA, &GPIO_InitStructure);//3õê¼»ˉ
//(¼ì2éêÇ·ñêÇÕy3£¿a)»ú
if(Check_WKUP()==0)
{
Sys_Enter_Standby(); //2»êÇ¿a»ú,½øèë′y»úÄ£ê½
}
SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOA, EXTI_PinSource0);//PA0 ᬽóμ½ÖD¶ÏÏß0
EXTI_InitStructure.EXTI_Line = EXTI_Line0;//LINE0
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;//ÖD¶Ïê¼t
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising; //éÏéyÑØ′¥·¢
EXTI_InitStructure.EXTI_LineCmd = ENABLE;//ê1ÄüLINE0
EXTI_Init(&EXTI_InitStructure);//ÅäÖÃ
NVIC_InitStructure.NVIC_IRQChannel = EXTI0_IRQn;//ía2¿ÖD¶Ï0
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x02;//ÇàÕ¼óÅÏ輶2
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x02;//×óóÅÏ輶2
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;//ê1Äüía2¿ÖD¶Ïí¨μà
NVIC_Init(&NVIC_InitStructure);//ÅäÖÃNVIC
}
给的教程里的程序,主函数就不粘贴了,我疑惑的是当处于待机状态时,长按3秒唤醒键会开机,此时不松开一直再持续3秒为什么不会再次进入待机状态?
一周热门 更多>