用万利的板子学M3,环境是MDK3.24,用NVIC,EXIT做两个按键分别控制两个LED的实验:KEY2控制LD1亮灭,KEY3控制LD3亮灭
一开始开了level 3的优化,结果只有KEY2控制LD1亮灭可以起作用,KEY3不起作用。
调了半天没有发现问题在哪里,两个按键,两个LED的设置是一模一样的。后来把优化给关了,就都正常了
哪位高手可以解释下吗?
程序中没有使用自己定义的变量
工程在这里:
http://www.ourdev.cn/bbs/bbs_upload540590/files_11/ourdev_503054.rar
EXTI的配置
void EXTI_Configuration(void)
{
EXTI_InitTypeDef EXTI_InitStructure;
/* Connect (Key Button EXTI Line to Key Button) GPIO Pin */
GPIO_EXTILineConfig(GPIO_PortSourceGPIOD, GPIO_PinSource3);
/* Configure Key Button EXTI Line to generate an interrupt on falling edge*/
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);
/* Connect (Key Button EXTI Line to Key Button) GPIO Pin */
GPIO_EXTILineConfig(GPIO_PortSourceGPIOD, GPIO_PinSource4);
/* Configure Key Button EXTI Line to generate an interrupt on falling edge */
EXTI_InitStructure.EXTI_Line = EXTI_Line4;
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
EXTI_Init(&EXTI_InitStructure);
}
NVIC的配置
void NVIC_Configuration(void)
{
NVIC_InitTypeDef NVIC_InitStructure;
#ifdef VECT_TAB_RAM
/* Set the Vector Table base location at 0x20000000 */
NVIC_SetVectorTable(NVIC_VectTab_RAM, 0x0);
#else /* VECT_TAB_FLASH */
/* Set the Vector Table base location at 0x08000000 */
NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x0);
#endif
/* Configure one bit for preemption priority */
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);
/* Enable the EXTI3 Interrupt*/
NVIC_InitStructure.NVIC_IRQChannel = EXTI3_IRQChannel;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
/* Enable the EXTI4 Interrupt */
NVIC_InitStructure.NVIC_IRQChannel = EXTI4_IRQChannel;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
GPIO的配置
void GPIO_Configuration(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
/* Configure (PC.04 -- PC.11) as (Output push-pull) */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4 | GPIO_Pin_5 |GPIO_Pin_6 | GPIO_Pin_7;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOC, &GPIO_InitStructure);
/* Configure (PD.03, PC.04, PC.11 -- PC.15 as input floating) */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3 | GPIO_Pin_4 | GPIO_Pin_11 | GPIO_Pin_12 |
GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOD, &GPIO_InitStructure);
}
下面是两个中断处理
void EXTI3_IRQHandler(void)
{
GPIO_WriteBit(GPIOC, GPIO_Pin_7, (BitAction)((1-GPIO_ReadOutputDataBit(GPIOC, GPIO_Pin_7))));
/* Clear the Key Button EXTI line pending bit */
EXTI_ClearITPendingBit(EXTI_Line3);
}
void EXTI4_IRQHandler(void)
{
GPIO_WriteBit(GPIOC, GPIO_Pin_5, (BitAction)((1-GPIO_ReadOutputDataBit(GPIOC, GPIO_Pin_5))));
/* Clear the Key Button EXTI line pending bit */
EXTI_ClearITPendingBit(EXTI_Line4);
}
|
|