小学生
最后登录1970-1-1
在线时间 小时
注册时间2018-7-21
|
楼主 |
发表于 2018-7-21 10:26:33
|
显示全部楼层
#include "bsp_exti.h"
static void EXTI_NVIC_Config(void)
{
NVIC_InitTypeDef NVIC_InitStruct;
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
NVIC_InitStruct.NVIC_IRQChannelPreemptionPriority=1;
NVIC_InitStruct.NVIC_IRQChannelSubPriority=1;
NVIC_InitStruct.NVIC_IRQChannelCmd=ENABLE;
//K1
NVIC_InitStruct.NVIC_IRQChannel=EXTI0_IRQn;
NVIC_Init(&NVIC_InitStruct);
//K2
NVIC_InitStruct.NVIC_IRQChannel=EXTI15_10_IRQn;
NVIC_Init(&NVIC_InitStruct);
}
void EXTI_Key_Config(void)
{
GPIO_InitTypeDef GPIO_InitStruct;
EXTI_InitTypeDef EXTI_InitStruct;
//配置中断优先级
EXTI_NVIC_Config();
//初始化按键K1、K2
RCC_APB2PeriphClockCmd(KEY1_INT_GPIO_CLK,ENABLE);
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_InitStruct.GPIO_Pin = KEY1_INT_GPIO_PIN;
GPIO_Init(KEY1_INT_GPIO_PORT,&GPIO_InitStruct);
//初始化EXTI
//K1
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO,ENABLE);
GPIO_EXTILineConfig(GPIO_PortSourceGPIOA,GPIO_PinSource0);
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);
//K2
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_InitStruct.GPIO_Pin = KEY2_INT_GPIO_PIN;
GPIO_Init(KEY2_INT_GPIO_PORT,&GPIO_InitStruct);
GPIO_EXTILineConfig(GPIO_PortSourceGPIOC,GPIO_PinSource13);
EXTI_InitStruct.EXTI_Line=EXTI_Line13;
EXTI_InitStruct.EXTI_Mode=EXTI_Mode_Interrupt;
EXTI_InitStruct.EXTI_Trigger=EXTI_Trigger_Falling;
EXTI_InitStruct.EXTI_LineCmd=ENABLE;
EXTI_Init(&EXTI_InitStruct);
}
|
|