STM32中断
1、初始化时钟
RCC_APB2PeriphClockCmd(AFIO,ENBALE)
2、将中断端口映射到中断线上
GPIO_EXTILineConfig(GPIO_PortSourceGPIOA,GPIO_PinSource0);
//中断分组;两个抢占优先级,两个相应优先级
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
3、初始化NVIC
//nvic初始化 ,函数NVIC_Init
NVIC_InitTypeDef NVIC_InitStructure;
EXTI_InitTypeDef EXTI_InitStructure;
NVIC_InitStructure.NVIC_IRQChannel=EXTI0_IRQn;
NVIC_InitStructure.NVIC_IRQChannelCmd=ENABLE;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=2;
NVIC_InitStructure.NVIC_IRQChannelSubPriority=3;
NVIC_Init(&NVIC_InitStructure);
4、初始化exit
//初始化-EXTI_Init
EXTI_InitStructure.EXTI_Line=EXTI_Line0;
EXTI_InitStructure.EXTI_LineCmd=ENABLE;
EXTI_InitStructure.EXTI_Mode=EXTI_Mode_Interrupt;
EXTI_InitStructure.EXTI_Trigger=EXTI_Trigger_Rising;
EXTI_Init(&EXTI_InitStructure);
二、写中断函数
void EXTI0_IRQHandler()
{
int i=0;
if(EXTI_GetITStatus(EXTI_Line0)==1)
{
delay_ms(10);
if(Key_up==1)
{
for (i=1;i<10;i++)
{
delay_ms(26588);
GPIO_Write(GPIOC,display1[i]);
delay_ms(26588);
delay_ms(26588);
}
}
}
EXTI_ClearITPendingBit(EXTI_Line0);
}