通过按键中断点灯实验,按键之后没有反应

2019-07-21 01:39发布

[mw_shl_code=c,true]我是想通过按键1触发中断,点亮两个LED等,我是按照原子哥第27讲外部中断实验来设置的,为什么按了按键之后没有反应呢?求各位大师指点[/mw_shl_code] [mw_shl_code=c,true]int main(void) { //???????????????è???ù????×???27???ù??????????????PPT???è?????? // u8 count=0; GPIO_InitTypeDef GPIO_InitStructure; EXTI_InitTypeDef EXTI_InitStructure; NVIC_InitTypeDef NVIC_InitStruct; NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2 ); RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG,ENABLE); RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA,ENABLE); //?????è????·???????IO???????? GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; GPIO_Init(GPIOA , &GPIO_InitStructure);//??PA5?è?????????????????? //?è??IO???????????????? SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOA , EXTI_PinSource5 ); //??????????????,??·??????? EXTI_InitStructure.EXTI_Line=EXTI_Line5; EXTI_InitStructure.EXTI_LineCmd=ENABLE; EXTI_InitStructure.EXTI_Mode=EXTI_Mode_Interrupt; EXTI_InitStructure.EXTI_Trigger=EXTI_Trigger_Falling; EXTI_Init(&EXTI_InitStructure); //????????·?×é???????????? NVIC_InitStruct.NVIC_IRQChannel=EXTI9_5_IRQn; NVIC_InitStruct.NVIC_IRQChannelCmd=ENABLE; NVIC_InitStruct.NVIC_IRQChannelPreemptionPriority=0; NVIC_InitStruct.NVIC_IRQChannelSubPriority=1; NVIC_Init(&NVIC_InitStruct); //??????±à??????·??????? // /* ????LED????????????*/ RCC_AHB1PeriphClockCmd(RCC_GPIO_LED, ENABLE); /*????LED????????GPIOF?±??*/ /* Configure LED Pins in output pushpull mode */ GPIO_InitStructure.GPIO_Pin = DS1_PIN|DS2_PIN|DS3_PIN|DS4_PIN; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; GPIO_Init(GPIO_LED, &GPIO_InitStructure); GPIO_SetBits(GPIO_LED ,DS1_PIN |DS2_PIN |DS3_PIN |DS4_PIN ); GPIO_ResetBits(GPIO_LED,DS4_PIN|DS1_PIN );/*??±??ù????LED??????*/ while(1) { // GPIO_SetBits(GPIO_LED,DS1_PIN|DS4_PIN);/*??±??ù????LED??????*/ } } [/mw_shl_code]
[mw_shl_code=c,true]void EXTI9_5_IRQHandler(void) { Delay(50); if(GPIO_ReadInputDataBit(GPIOA ,GPIO_Pin_5 )==1) { GPIO_ResetBits(GPIO_LED,DS1_PIN); GPIO_ResetBits(GPIO_LED,DS2_PIN); } EXTI_ClearITPendingBit(EXTI_Line5 ); }[/mw_shl_code]
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。