你的浏览器版本过低,可能导致网站不能正常访问!
为了你能正常使用网站功能,请使用这些浏览器。

关于MDK中优化的问题,优化后程序出错

[复制链接]
yycool 提问时间:2008-11-18 14:47 /
用万利的板子学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);


收藏 评论0 发布时间:2008-11-18 14:47

举报

0个回答

所属标签

相似问题

关于
我们是谁
投资者关系
意法半导体可持续发展举措
创新与技术
意法半导体官网
联系我们
联系ST分支机构
寻找销售人员和分销渠道
社区
媒体中心
活动与培训
隐私策略
隐私策略
Cookies管理
行使您的权利
官方最新发布
STM32Cube扩展软件包
意法半导体边缘AI套件
ST - 理想汽车豪华SUV案例
ST意法半导体智能家居案例
STM32 ARM Cortex 32位微控制器
关注我们
st-img 微信公众号
st-img 手机版