为什么我的stm32中断处理程序没有响应?
PA1->LED1 PA2->LED2
PC0->KEY1 PC1->KEY2
主程序
#include "stm32f10x.h"
#include "stm32f10x_conf.h"
extern void Delay(vu32 nCount);
void RCC_Config(void);
void GPIO_Config(void);
void EXTI_Config(void);
void NVIC_Config(void);
int main(void)
{
//SystemInit();
RCC_Config();
GPIO_Config();
EXTI_Config();
NVIC_Config();
while (1)
{
}
}
void RCC_Config(void)
{
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA|RCC_APB2Periph_GPIOC|RCC_APB2Periph_AFIO, ENABLE);
/*开时钟*/
}
void GPIO_Config(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitStructure.GPIO_Pin =GPIO_Pin_1|GPIO_Pin_2;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin =GPIO_Pin_0|GPIO_Pin_1;//KEY
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
GPIO_Init(GPIOC, &GPIO_InitStructure);
}
void EXTI_Config(void)
{
GPIO_EXTILineConfig(GPIO_PortSourceGPIOC, GPIO_PinSource0);
EXTI_InitTypeDef EXTI_InitStructure;
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);
GPIO_EXTILineConfig(GPIO_PortSourceGPIOC, GPIO_PinSource1);
EXTI_InitStructure.EXTI_Line = EXTI_Line1;
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;//下降沿
EXTI_InitStructure.EXTI_LineCmd = ENABLE;//中断使能
EXTI_Init(&EXTI_InitStructure);
}
void NVIC_Config(void)//中断嵌套优先级设置
{
NVIC_InitTypeDef NVIC_InitStructure;
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);//1组
/* Enable the EXTI0_IRQn Interrupt */
NVIC_InitStructure.NVIC_IRQChannel = EXTI0_IRQn;//0
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
/* Enable the EXTI1 Interrupt */
NVIC_InitStructure.NVIC_IRQChannel = EXTI1_IRQn;//1
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
中断处理程序
void EXTI0_IRQHandler(void)
{
int i;
if(EXTI_GetITStatus(EXTI_Line0) != RESET)
{
/* Clear the Key Button EXTI line pending bit */
EXTI_ClearITPendingBit(EXTI_Line0);//清中断标志位
for(i=0;i<2;i++)
{
GPIO_SetBits(GPIOA, GPIO_Pin_1);//GPIOB.5=1
Delay(0xfffff);
GPIO_SetBits(GPIOA, GPIO_Pin_2);//GPIOB.6=1
Delay(0xfffff);
GPIO_ResetBits(GPIOA, GPIO_Pin_1);//GPIOB.5=0
Delay(0xfffff);
GPIO_ResetBits(GPIOA, GPIO_Pin_2);//GPIOB.6=0
Delay(0xfffff);
}
}
}
void EXTI1_IRQHandler(void)
{
int i;
if(EXTI_GetITStatus(EXTI_Line1) != RESET)
{
/* Clear the Key Button EXTI line pending bit */
EXTI_ClearITPendingBit(EXTI_Line1);//清中断标志位
for(i=0;i<2;i++)
{
GPIO_SetBits(GPIOA, GPIO_Pin_1);//GPIOB.7=1
Delay(0xfffff);
GPIO_SetBits(GPIOA, GPIO_Pin_2);//GPIOC.8=1
Delay(0xfffff);
GPIO_ResetBits(GPIOA, GPIO_Pin_1);//GPIOB.7=0
Delay(0xfffff);
GPIO_ResetBits(GPIOA, GPIO_Pin_2);//GPIOB.8=0
Delay(0xfffff);
}
}
}
extern void Delay(vu32 nCount) //简单的长时间延时函数
{
int i; //声明内部递减变量
for(; nCount!= 0; nCount--) //递减变量计数
{
for (i=0; i<0xffff; i++);
}
}
文章评论(0条评论)
登录后参与讨论