小学生
最后登录1970-1-1
在线时间 小时
注册时间2021-9-22
|
#include "exti.h" //key0 PE4
static void NVIC_EXTI_Config(void)
{
NVIC_PriorityGroupConfig( NVIC_PriorityGroup_1);
NVIC_InitTypeDef NVIC_InitStruct;
NVIC_InitStruct.NVIC_IRQChannel = EXTI4_IRQn;
NVIC_InitStruct.NVIC_IRQChannelPreemptionPriority = 1;
NVIC_InitStruct.NVIC_IRQChannelSubPriority = 1;
NVIC_InitStruct.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStruct);
}
void EXTI_KEY_Config(void)
{
GPIO_InitTypeDef GPIO_InitStruct;
EXTI_InitTypeDef EXTI_InitStruct;
//key0初始化 PE4
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOE, ENABLE);
GPIO_InitStruct.GPIO_Mode=GPIO_Mode_IN_FLOATING;
GPIO_InitStruct.GPIO_Pin=GPIO_Pin_4;
GPIO_Init(GPIOE, &GPIO_InitStruct);
//NVIC初始化
NVIC_EXTI_Config();
//将key0连接到EXTI上面去
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE);
GPIO_EXTILineConfig(GPIO_PortSourceGPIOE, GPIO_PinSource4);
//初始化EXTI
EXTI_InitStruct.EXTI_Line = EXTI_Line4;
EXTI_InitStruct.EXTI_Mode = EXTI_Mode_Interrupt;
EXTI_InitStruct.EXTI_Trigger = EXTI_Trigger_Rising;
EXTI_InitStruct.EXTI_LineCmd = ENABLE;
EXTI_StructInit(&EXTI_InitStruct);
}
//这是对应执行的中断服务子程序
void EXTI4_IRQHandler(void)
{
if( EXTI_GetITStatus(EXTI_Line4) != RESET)
{
LED0_TOGGLE;
}
EXTI_ClearITPendingBit(EXTI_Line4);
}
|
|