error: #268: declaration may not appear after executabl statement in block

小白的问题:stm32用keil4编译时出现:error:  #268: declaration may not appear after executabl statement in block

        出现这个错误的原因在于C语言关于变量的定义只能放在函数的开头,应该放在执行语句的前面定义,才不会出错~

例如函数void TIM_Config(void)
{
         TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;


TIM_DeInit(TIM2);
TIM_InternalClockConfig(TIM2);

TIM_TimeBaseStructure.TIM_Prescaler=36000;
TIM_TimeBaseStructure.TIM_Period=65535;
TIM_TimeBaseStructure.TIM_ClockDivision=0x0;
TIM_TimeBaseStructure.TIM_CounterMode=TIM_CounterMode_Up;
TIM_TimeBaseInit(TIM2,&TIM_TimeBaseStructure);

TIM_OCInitTypeDef       TIM_OCInitStructure;
TIM_OCInitStructure.TIM_OCMode=TIM_OCMode_Timing;
TIM_OCInitStructure.TIM_Pulse=2000;
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
TIM_OCInitStructure.TIM_OCPolarity=TIM_OCPolarity_High;
TIM_OC1Init(TIM2,&TIM_OCInitStructure);
TIM_OC1PreloadConfig(TIM2,TIM_OCPreload_Disable);

}

这样编译就会出现上面所说的错误,应该把TIM_OCInitTypeDef       TIM_OCInitStructure;这个语句放在函数开头,即可解决;

你可能感兴趣的:(stm32,C语言)