在进行STM32程序调试时,发现按下中断按键时,程序始终停在一个状态(LED1亮/灭),不知道在中断时为什么会出现这样的现象,各位大侠帮帮忙,万分感谢。
程序代码如下:
#include "stm32f10x_lib.h"
GPIO_InitTypeDef GPIO_InitStructure;
EXTI_InitTypeDef EXTI_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
/* Private function prototypes -----------------------------------------------*/
void GPIO_Configuration(void);
void NVIC_Configuration(void);
void Delay(vu32 nCount);
/* Private functions ---------------------------------------------------------*/
int main(void)
{
//SystemInit();
GPIO_Configuration();
NVIC_Configuration();
RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE);
/* Connect EXTI Line0 to PA.0 */
GPIO_EXTILineConfig(GPIO_PortSourceGPIOA, GPIO_PinSource0);
/* Configure EXTI Line0 to generate an interrupt on falling edge */
EXTI_InitStructure.EXTI_Line = EXTI_Line0;
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
EXTI_Init(&EXTI_InitStructure);
// PWR_EnterSTOPMode(PWR_Regulator_ON, PWR_STOPEntry_WFI);
while(1)
{
GPIO_SetBits(GPIOA, GPIO_Pin_1);//点亮LED
Delay(0x3ffff); //延时
GPIO_ResetBits(GPIOA, GPIO_Pin_1);//关闭LED
Delay(0x3ffff); //延时
}
}
void GPIO_Configuration(void)
{
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1 ;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //带上拉输出
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; //输出频率最大50M
GPIO_Init(GPIOA, &GPIO_InitStructure); //初始化
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0; //选择引脚0
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; //浮点输入
GPIO_Init(GPIOA, &GPIO_InitStructure); //初始化PA0引脚
}
void NVIC_Configuration(void)
{
NVIC_InitTypeDef NVIC_InitStructure;
NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x0);
/* Configure one bit for preemption priority */
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);
/* Enable the EXTI0 Interrupt */
NVIC_InitStructure.NVIC_IRQChannel = EXTI0_IRQChannel;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
void Delay(vu32 nCount)
{
for(; nCount != 0; nCount--);
}
在文件“stm32f10x_it.c”中,按下中断按键时可以进入
void EXTI0_IRQHandler(void)
{
// GPIO_SetBits(GPIOA, GPIO_Pin_1);//点亮LED2
}
此函数,但继续运行就不到跑哪里去了,头真晕啊~~~·
一个为理想不懈前进的人,一个永不言败人!
http://shop57496282.taobao.com/
欢迎光临网上店铺!
回复 楼主 eeleader 的帖子
怎么不把中断标记清除呢?
if(EXTI_GetITStatus(EXTI_Line0)!=RESET)
{
EXTI_ClearITPendingBit(EXTI_Line0);
}