/*bsp_exti.c文件*/
#include "bsp_exti.h"
static void EXIT_NVIC_Config(void)
{
NVIC_InitTypeDef NVIC_InitStruct;
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);
NVIC_InitStruct.NVIC_IRQChannel=EXTI0_IRQn;
NVIC_InitStruct.NVIC_IRQChannelPreemptionPriority=1;
NVIC_InitStruct.NVIC_IRQChannelSubPriority=1;
NVIC_InitStruct.NVIC_IRQChannelCmd=ENABLE;
NVIC_Init(&NVIC_InitStruct);
NVIC_InitStruct.NVIC_IRQChannel=EXTI15_10_IRQn;
NVIC_Init(&NVIC_InitStruct);
}
void EXIT_Key_Config(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
EXTI_InitTypeDef EXTI_InitStructure;
/*配置中断优先级*/
EXIT_NVIC_Config();
/*初始化KEY1要连接到EXTI的GPIO*/
RCC_APB2PeriphClockCmd(KEY1_INT_GPIO_CLK,ENABLE);
GPIO_InitStructure.GPIO_Pin = KEY1_INT_GPIO_PIN;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(KEY1_INT_GPIO_PORT, &GPIO_InitStructure);
/*初始化KEY2要连接到EXTI的GPIO*/
RCC_APB2PeriphClockCmd(KEY2_INT_GPIO_CLK,ENABLE);
GPIO_InitStructure.GPIO_Pin = KEY2_INT_GPIO_PIN;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(KEY2_INT_GPIO_PORT, &GPIO_InitStructure);
GPIO_EXTILineConfig(GPIO_PortSourceGPIOA, GPIO_PinSource0);
EXTI_InitStructure.EXTI_Line=EXTI_Line0;
EXTI_InitStructure.EXTI_LineCmd=ENABLE;
EXTI_InitStructure.EXTI_Mode=EXTI_Mode_Interrupt;
EXTI_InitStructure.EXTI_Trigger=EXTI_Trigger_Rising;
EXTI_Init(&EXTI_InitStructure);
GPIO_EXTILineConfig(GPIO_PortSourceGPIOC, GPIO_PinSource13);
EXTI_InitStructure.EXTI_Line = EXTI_Line13;
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising;
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
EXTI_Init(&EXTI_InitStructure);
}
/*bsp_exti.h文件*/
#ifndef _BSP_EXTI_H
#define _BSP_EXTI_H
#include "stm32f10x.h"
/*KEY1有关的接口宏定义*/
#define KEY1_INT_GPIO_PORT GPIOA
#define KEY1_INT_GPIO_CLK RCC_APB2Periph_GPIOA
#define KEY1_INT_GPIO_PIN GPIO_Pin_0
#define KEY2_INT_GPIO_PORT GPIOC
#define KEY2_INT_GPIO_CLK RCC_APB2Periph_GPIOC
#define KEY2_INT_GPIO_PIN GPIO_Pin_13
void EXIT_Key_Config(void);
#endif /* _BSP_EXTI_H*/
/*stm32F10x_it.c文件*/
void SysTick_Handler(void)
{
}
void EXTI0_IRQHandler(void)
{
if(EXTI_GetITStatus(EXTI_Line0)!=RESET)
{
LED1_TOGGLE;
}
EXTI_ClearITPendingBit(EXTI_Line0);
}
void EXTI15_10_IRQHandler(void)
{
if(EXTI_GetITStatus(EXTI_Line13)!=RESET)
{
LED2_TOGGLE;
}
EXTI_ClearITPendingBit(EXTI_Line13);
}
程序运行KEY1正常,KEY2无响应,请问是为什么? |