代码拉取完成,页面将自动刷新
同步操作将从 think3r/STM32F103_ch376_uart 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
#include "exti_key.h"
#include "../STM32_FWLIB/inc/stm32f10x_exti.h"
#include "../HardWare/include.h"
#include "./ch376s/HOST.H"
static void KEY_Init(void) //IO初始化
{
//定义初始化gpio的结构体
GPIO_InitTypeDef GPIO_initstruct;
//初始化端口时钟,使能POARTA & POARTC 的时钟
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA|RCC_APB2Periph_GPIOC,ENABLE);
//初始化按键 key0 PC1 上拉输入'
GPIO_initstruct.GPIO_Speed=
GPIO_Speed_2MHz;
GPIO_initstruct.GPIO_Pin = GPIO_Pin_1;
GPIO_initstruct.GPIO_Mode = GPIO_Mode_IPU;
GPIO_Init(GPIOC,&GPIO_initstruct);
//初始化按键 key1 PC13 上拉输入
GPIO_initstruct.GPIO_Pin = GPIO_Pin_13;
GPIO_Init(GPIOC,&GPIO_initstruct);
//初始化按键 wk_up PA0 下拉输入
GPIO_initstruct.GPIO_Mode = GPIO_Mode_IPD;
GPIO_initstruct.GPIO_Pin = GPIO_Pin_0;
GPIO_Init(GPIOA,&GPIO_initstruct);
}
void EXTIX_Key_Init(void)
{
EXTI_InitTypeDef EXTI_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
KEY_Init(); // 按键端口 GPIO 初始化
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO,ENABLE); //使能复用功能时钟
//----------------------------------------------------------------------------------------
//GPIOC.1 key0 中断线以及中断初始化配置 下降沿触发
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); //根据EXTI_InitStruct中指定的参数初始化外设EXTI寄存器
//GPIOC.13 key1 中断线以及中断初始化配置 下降沿触发
GPIO_EXTILineConfig(GPIO_PortSourceGPIOC,GPIO_PinSource13);
EXTI_InitStructure.EXTI_Line = EXTI_Line13;
EXTI_Init(&EXTI_InitStructure);
//GPIOA.0 WK_UP 中断线以及中断初始化配置 上升沿触发 PA0
GPIO_EXTILineConfig(GPIO_PortSourceGPIOA,GPIO_PinSource0);
EXTI_InitStructure.EXTI_Line = EXTI_Line0;
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising;
EXTI_Init(&EXTI_InitStructure); //根据EXTI_InitStruct中指定的参数初始化外设EXTI寄存器
//----------------------------------------------------------------------------
//GPIOC.1 key0
NVIC_InitStructure.NVIC_IRQChannel = EXTI1_IRQn; //使能按键key0所在的外部中断通道
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x02; //抢占优先级2,
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x03; //子优先级3
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //使能外部中断通道
NVIC_Init(&NVIC_InitStructure);
//GPIOC.13 key1
NVIC_InitStructure.NVIC_IRQChannel = EXTI15_10_IRQn; //使能按键key1所在的外部中断通道
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x02; //抢占优先级2,
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x03; //子优先级3
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //使能外部中断通道
NVIC_Init(&NVIC_InitStructure);
//GPIOA.0 WK_UP
NVIC_InitStructure.NVIC_IRQChannel = EXTI0_IRQn; //使能按键WK_UP所在的外部中断通道
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x02; //抢占优先级2,
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x02; //子优先级3
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //使能外部中断通道
NVIC_Init(&NVIC_InitStructure);
printf("按键中断初始化成功!\r\n");
}
//外部中断 1 服务程序 按键 key0
void EXTI1_IRQHandler(void)
{
delay_ms(20);//消抖
if(KEY0==0) //按键KEY2
{
led0 = !led0;
printf("按键 key0 被按下。\r\n");
}
EXTI_ClearITPendingBit(EXTI_Line1); //清除LINE1上的中断标志位
}
//外部中断 13 服务程序 按键 key1
void EXTI15_10_IRQHandler(void)
{
if(EXTI_GetITStatus(EXTI_Line13))
{
delay_ms(20);
if(KEY1==0)
{
led1 = !led1;
printf("按键 KEY1 被按下。\r\n");
}
EXTI_ClearITPendingBit(EXTI_Line13); //清除LINE13上的中断标志位
}
}
//外部中断 0 服务程序 按键WK_UP
void EXTI0_IRQHandler(void)
{
delay_ms(5);//消抖
if(WK_UP==1) //WK_UP按键
{
SafeRemoveDisk();
printf("按键 WK_UP 被按下。\r\n");
}
EXTI_ClearITPendingBit(EXTI_Line0); //清除LINE0上的中断标志位
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。