分享一下中断程序:
void EXTIX_Init(void)
{
GPIO_InitTypeDef GPIO_InitStructure; //定义端口结构初始化
EXTI_InitTypeDef EXTI_InitStructure; //定义中断结构初始化
NVIC_InitTypeDef NVIC_InitStructure; //定义中断优先级结构初始化
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB|RCC_APB2Periph_GPIOC|RCC_APB2Periph_AFIO,ENABLE);
GPIO_PinRemapConfig(GPIO_Remap_SWJ_Disable, ENABLE); //改变指定管脚的映射 GPIO_Remap_SWJ_Disable SWJ
PIO_PinRemapConfig(GPIO_Remap_SWJ_JTAGDisable, ENABLE); //改变指定管脚的映射GPIO_Remap_SWJ_JTAGDisable
//初始化KEY01-> PB5, KEY00->PB4 设置为输出
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4 | GPIO_Pin_5;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(GPIOB, &GPIO_InitStructure);
KEY01 = 1;
KEY00 = 0;
//初始化KEY13->PB3 设置为输入
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
GPIO_Init(GPIOB, &GPIO_InitStructure);
//初始化KEY12->PC12, KEY11->PC11, KEY10->PC10,设置为输入
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12|GPIO_Pin_11|GPIO_Pin_10;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
GPIO_Init(GPIOC, &GPIO_InitStructure);
GPIO_EXTILineConfig(GPIO_PortSourceGPIOB, GPIO_PinSource3);
EXTI_InitStructure.EXTI_Line = EXTI_Line3;
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
EXTI_Init(&EXTI_InitStructure);
GPIO_EXTILineConfig(GPIO_PortSourceGPIOC, GPIO_PinSource12);
GPIO_EXTILineConfig(GPIO_PortSourceGPIOC, GPIO_PinSource11);
GPIO_EXTILineConfig(GPIO_PortSourceGPIOC, GPIO_PinSource10);
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_InitStructure.EXTI_Line = EXTI_Line11;
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
EXTI_Init(&EXTI_InitStructure);
EXTI_InitStructure.EXTI_Line = EXTI_Line10;
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
EXTI_Init(&EXTI_InitStructure);
NVIC_InitStructure.NVIC_IRQChannel = EXTI3_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x02;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x01;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
NVIC_InitStructure.NVIC_IRQChannel = EXTI15_10_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x02;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x02;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
void EXTI3_IRQHandler(void)
{
if(EXTI_GetITStatus(EXTI_Line3) !=RESET)
{LED4 =!LED4;}
EXTI_ClearITPendingBit(EXTI_Line3);}
void EXTI15_10_IRQHandler(void)
{
if (EXTI_GetITStatus(EXTI_Line12) !=RESET)
{LED3 =!LED3;}
else if (EXTI_GetITStatus(EXTI_Line11) !=RESET)
{LED2 =!LED2; }
else if (EXTI_GetITStatus(EXTI_Line10) !=RESET)
{LED1 =!LED1;}
EXTI_ClearITPendingBit(EXTI_Line12); //清除EXTI线路挂起位
EXTI_ClearITPendingBit(EXTI_Line11); //清除EXTI线路挂起位
EXTI_ClearITPendingBit(EXTI_Line10); //清除EXTI线路挂起位}
文章评论(0条评论)
登录后参与讨论