初级会员

- 积分
- 74
- 金钱
- 74
- 注册时间
- 2012-1-12
- 在线时间
- 2 小时
|

楼主 |
发表于 2012-2-18 16:38:58
|
显示全部楼层
回复【4楼】正点原子:
---------------------------------
我在改写以上代码为调用库函数时,WKUP可以唤醒待机,但是之后就进入systick延时死循环,请问原子哥能不能指点一下:
#include "stm32f10x.h"
#include <stdio.h>
#include "wkup.h"
#include "led.h"
#include "systick.h"
//系统进入待机模式
void Sys_Enter_Standby(void)
{
//关闭所有外设(根据实际情况写)
RCC->APB2RSTR|=0X01FC;//复位所有IO口
PWR_EnterSTANDBYMode();//进入待机模式
}
//检测WKUP脚的信号
//返回值1:连续按下3s以上
// 0:错误的触发
uint8_t Check_WKUP(void)
{
uint8_t t=0;
uint8_t tx=0;//记录松开的次数
GPIO_ResetBits(GPIOF, GPIO_Pin_6); //亮灯LED1
while(1)
{
if(WKUP_KD())//已经按下了
{
t++;
tx=0;
}else
{
tx++; //超过300ms内没有WKUP信号
if(tx>3)
{
GPIO_SetBits(GPIOF, GPIO_Pin_6);
return 0;//错误的按键,按下时间不够
}
}
DelayMS(30);
if(t>=100)//按下超过3秒钟
{
GPIO_ResetBits(GPIOF, GPIO_Pin_6); //点亮LED1
return 1; //按下3s以上了
}
}
}
//中断,检测到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;
EXTI_InitTypeDef EXTI_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE); //先使能外设IO  ORTA时钟
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE); //开启辅助时钟
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPD;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);//PA0设置成输入
/* Connect EXTI Line0 to  A.0 */
GPIO_EXTILineConfig(GPIO_PortSourceGPIOA, GPIO_PinSource0);
/* Configure EXTI Line0 to generate an interrupt on rising edge */
EXTI_InitStructure.EXTI_Line = EXTI_Line0;
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising;
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
EXTI_Init(&EXTI_InitStructure);
//(检查是否是正常开)机
if(Check_WKUP()==0)PWR_EnterSTANDBYMode(); //不是开机,进入待机模式
/* Configure one bit for preemption priority */
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
/* Enable the EXTI0 Interrupt */
NVIC_InitStructure.NVIC_IRQChannel = EXTI0_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 2;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 2;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
/* Generate software interrupt: simulate a rising edge applied on Key Button EXTI line */
EXTI_GenerateSWInterrupt(EXTI_Line0);
}
uint8_t WKUP_KD(void)
{
if (GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_0) == Bit_SET) return 1;
return 0;
} |
|