代码如下 我用小灯检测有没有进入中断,就是进不去 。用万用表测了 我按键按下的时候 A6 电平确实被拉低 了。
void EX
tiX_Init(void)
{
EXTI_InitTypeDef EXTI_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO,ENABLE);//ÍⲿÖжϣ¬ÐèҪʹÄÜAFIOʱÖÓ
GPIO_EXTILineConfig(GPIO_PortSourceGPIOA,GPIO_PinSource6);
EXTI_InitStructure.EXTI_Line=EXTI_Line6;
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¼Ä´æÆ÷
NVIC_InitStructure.NVIC_IRQChannel = EXTI9_5_IRQn; //ʹÄÜ°´¼üËùÔÚµÄÍⲿÖжÏͨµÀ
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x02; //ÇÀÕ¼ÓÅÏȼ¶2£¬
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x01; //×ÓÓÅÏȼ¶1
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //ʹÄÜÍⲿÖжÏͨµÀ
NVIC_Init(&NVIC_InitStructure);
}
void EXTI9_5_IRQHandler(void)
{
LED0=0;
// if(EXTI_GetITStatus(EXTI_Line5)!=RESET)
// {
// cnt++;
// if(cnt==4000);
// {
//
// TIM_Cmd(TIM3,DISABLE);
// cnt=0;
//
// }
//}
EXTI_ClearITPendingBit(EXTI_Line6);
}
void LED_Init(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE); //ʹÄÜPA,PD¶Ë¿ÚʱÖÓ
GPIO_PinRemapConfig(GPIO_Remap_SWJ_JTAGDisable, ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6; //LED0-->PA.8 ¶Ë¿ÚÅäÖÃ
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //ÍÆÍìÊä³ö
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; //IO¿ÚËÙ¶ÈΪ50MHz
GPIO_Init(GPIOA, &GPIO_InitStructure); //¸ù¾ÝÉ趨²ÎÊý³õʼ»¯GPIOA.8
GPIO_SetBits(GPIOA,GPIO_Pin_6); //PA.8 Êä³ö¸ß
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0; //LED0-->PA.8 ¶Ë¿ÚÅäÖÃ
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //ÍÆÍìÊä³ö
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; //IO¿ÚËÙ¶ÈΪ50MHz
GPIO_Init(GPIOA, &GPIO_InitStructure); //¸ù¾ÝÉ趨²ÎÊý³õʼ»¯GPIOA.8
GPIO_SetBits(GPIOA,GPIO_Pin_0);
}
一周热门 更多>