[mw_shl_code=c,true]void EXTI_GPIO_Init(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOF,ENABLE);
GPIO_InitStructure.GPIO_Pin=GPIO_Pin_6|GPIO_Pin_7|GPIO_Pin_8|GPIO_Pin_9;
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_IN;//使用输入模式
GPIO_InitStructure.GPIO_PuPd=GPIO_PuPd_UP;//上拉模式
GPIO_InitStructure.GPIO_Speed=GPIO_Speed_100MHz;
GPIO_Init(GPIOF,&GPIO_InitStructure);
}
void EXTIX_Init(void)
{
EXTI_InitTypeDef EXTI_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
EXTI_GPIO_Init();
RCC_AHB2PeriphClockCmd(RCC_APB2Periph_SYSCFG,ENABLE);
SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOF,EXTI_PinSource6);
SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOF,EXTI_PinSource7);
EXTI_InitStructure.EXTI_Line=EXTI_Line6|EXTI_Line7;//使能中断线6、7
EXTI_InitStructure.EXTI_Mode=EXTI_Mode_Interrupt;//中断事件
EXTI_InitStructure.EXTI_Trigger=EXTI_Trigger_Rising_Falling;//上升沿+下降沿触发
EXTI_InitStructure.EXTI_LineCmd=ENABLE;//使能中断
EXTI_Init(&EXTI_InitStructure);//初始化中断
NVIC_InitStructure.NVIC_IRQChannel = EXTI9_5_IRQn;//外部中断中断通道
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=1;//抢占优先级1
NVIC_InitStructure.NVIC_IRQChannelSubPriority =1; //子优先级1
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //IRQ通道使能
NVIC_Init(&NVIC_InitStructure); //根据指定的参数初始化VIC寄存器、
}
void EXTI9_5_IRQHandler(void)
{
delay_ms(20);
if(PFin(6)==0)
{
LED1=~LED1;
}
if(PFin(7)==0)
{
LED1=~LED1;
}
EXTI_ClearITPendingBit(EXTI_Line6|EXTI_Line7);
}[/mw_shl_code]
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
一周热门 更多>