高中生
最后登录1970-1-1
在线时间 小时
注册时间2016-5-9
|
#include "bsp_exti.h"
void EXTI_NVIC_Config (void);
void KEY_EXTI_Config(void)
{
GPIO_InitTypeDef GPIO_InitStruct;
EXTI_InitTypeDef EXTI_InitStruct;
EXTI_NVIC_Config ();
//打开KEY1的时钟
RCC_APB2PeriphClockCmd(KEY1_EXTI_GPIO_CLK , ENABLE);
//配置KEY1为浮空输入
GPIO_InitStruct.GPIO_Pin = KEY1_EXTI_GPIO_PIN;
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(KEY1_EXTI_GPIO_PORT, &GPIO_InitStruct);
//打开KEY2的时钟
RCC_APB2PeriphClockCmd(KEY2_EXTI_GPIO_CLK , ENABLE);
//配置KEY2为浮空输入
GPIO_InitStruct.GPIO_Pin = KEY2_EXTI_GPIO_PIN;
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(KEY2_EXTI_GPIO_PORT, &GPIO_InitStruct);
//打开AFIO时钟
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO , ENABLE);
//初始化KEY1_EXTI 上升沿有效
EXTI_InitStruct.EXTI_Line = EXTI_Line0;
EXTI_InitStruct.EXTI_Mode = EXTI_Mode_Interrupt;
EXTI_InitStruct.EXTI_Trigger = EXTI_Trigger_Rising;
EXTI_InitStruct.EXTI_LineCmd = ENABLE;
EXTI_Init(&EXTI_InitStruct);
//初始化KEY2_EXTI 下降沿有效
EXTI_InitStruct.EXTI_Line = EXTI_Line13;
EXTI_InitStruct.EXTI_Mode = EXTI_Mode_Interrupt;
EXTI_InitStruct.EXTI_Trigger = EXTI_Trigger_Rising;
EXTI_InitStruct.EXTI_LineCmd = ENABLE;
EXTI_Init(&EXTI_InitStruct);
}
//配置中断优先级函数
void EXTI_NVIC_Config (void)
{
NVIC_InitTypeDef NVIC_InitStruct;
//配置KEY1
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);
//配置KEY2
NVIC_InitStruct.NVIC_IRQChannel = EXTI15_10_IRQn;
NVIC_InitStruct.NVIC_IRQChannelPreemptionPriority = 1;
NVIC_InitStruct.NVIC_IRQChannelSubPriority = 1;
NVIC_InitStruct.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStruct);
}
我是照着KEY1初始化KEY2的 但是KEY1能用KEY2不能用 求助
下面是中断函数
void EXTI0_IRQHandler (void)
{
if(EXTI_GetITStatus(EXTI_Line0) != RESET)
{
LED_G_TOGGLE;
}
EXTI_ClearITPendingBit(EXTI_Line0);
}
void EXTI15_10_IRQHandler (void)
{
if(EXTI_GetITStatus(EXTI_Line13) != RESET)
{
LED_G_TOGGLE;
}
EXTI_ClearITPendingBit(EXTI_Line13);
}
|
|