/*********************************************** 公司:轮趣科技(东莞)有限公司 品牌:WHEELTEC 官网:wheeltec.net 淘宝店铺:shop114407458.taobao.com 速卖通: https://minibalance.aliexpress.com/store/4455017 版本:5.7 修改时间:2021-04-29 Brand: WHEELTEC Website: wheeltec.net Taobao shop: shop114407458.taobao.com Aliexpress: https://minibalance.aliexpress.com/store/4455017 Version:5.7 Update:2021-04-29 All rights reserved ***********************************************/ #include "exti.h" /************************************************************************** Function: External interrupt initialization Input : none Output : none 函数功能:外部中断初始化 入口参数:无 返回 值:无 **************************************************************************/ void MiniBalance_EXTI_Init(void) { GPIO_InitTypeDef GPIO_InitStructure; EXTI_InitTypeDef EXTI_InitStructure; NVIC_InitTypeDef NVIC_InitStructure; RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO,ENABLE); //外部中断,需要使能AFIO时钟 RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE); //使能GPIO端口时钟 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12; //端口配置 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU; //上拉输入 GPIO_Init(GPIOA, &GPIO_InitStructure); //根据设定参数初始化GPIO GPIO_EXTILineConfig(GPIO_PortSourceGPIOA,GPIO_PinSource12); EXTI_InitStructure.EXTI_Line=EXTI_Line12; EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt; EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;//下降沿触发 EXTI_InitStructure.EXTI_LineCmd = ENABLE; EXTI_Init(&EXTI_InitStructure); //根据EXTI_InitStruct中指定的参数初始化外设EXTI寄存器 NVIC_InitStructure.NVIC_IRQChannel = EXTI15_10_IRQn; //使能按键所在的外部中断通道 NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x02; //抢占优先级2, NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x01; //子优先级1 NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //使能外部中断通道 NVIC_Init(&NVIC_InitStructure); }