int main(void) { const unsigned char *point; u16 i=0; delay_init(); //ÑÓʱº¯Êý³õʼ»¯ NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);//ÉèÖÃÖжÏÓÅÏȼ¶·Ö×éΪ×é2£º2λÇÀÕ¼ÓÅÏȼ¶£¬2λÏìÓ¦ÓÅÏȼ¶ // uart_init(115200); //´®¿Ú³õʼ»¯Îª115200 LED_Init(); //³õʼ»¯ÓëLEDÁ¬½ÓµÄÓ²¼þ½Ó¿Ú // KEY_Init(); //°´¼ü³õʼ»¯ AT24CXX_Init(); //IIC³õʼ»¯ OLED_init(); point= &picture_tab[0]; TIM_OCInitTypeDef TIM_OCInitStructure; delay_init(); //ÑÓʱº¯Êý³õʼ»¯ NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2); //ÉèÖÃNVICÖжϷÖ×é2:2λÇÀÕ¼ÓÅÏȼ¶£¬2λÏìÓ¦ÓÅÏȼ¶ uart_init(115200); //´®¿Ú³õʼ»¯Îª115200 LED_Init(); //LED¶Ë¿Ú³õʼ»¯ TIM3_Int_Init(4999,7199);//10KhzµÄ¼ÆÊýƵÂÊ£¬¼ÆÊýµ½5000Ϊ500ms TIM4_PWM_Init(10000-1,72-1); //72M/72=1MHz¼ÆÊýƵÂÊ,ÖØ×°ÔØÖµ while(1) { OLED_ShowString(0,30,"21221054",16); OLED_ShowString(0,15,"2023/5/18",16); OLED_ShowChinese(0,0,0,16,1); OLED_ShowChinese(16,0,1,16,1); OLED_ShowChinese(32,0,2,16,1); delay_ms(1000); OLED_Refresh_Gram(); //¸üÐÂÏÔʾµ½OLED if(++i > 3) { LED1=!LED1;//ÌáʾϵͳÕýÔÚÔËÐÐ i=0; } while(1) { u16 u16tmp; u16tmp += 500; if(u16tmp > 10000) u16tmp=0; //³õʼ»¯TIM4 Channe3 PWMģʽ TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1; //Ñ¡Ôñ¶¨Ê±Æ÷ģʽ:TIMÂö³å¿í¶Èµ÷ÖÆģʽ2 TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable; //±È½ÏÊä³öʹÄÜ TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_Low; //Êä³ö¼«ÐÔ:TIMÊä³ö±È½Ï¼«ÐÔ¸ß TIM_OCInitStructure.TIM_Pulse = u16tmp; TIM_OC3Init(TIM4, &TIM_OCInitStructure); //¸ù¾ÝTÖ¸¶¨µÄ²ÎÊý³õʼ»¯ÍâÉèTIM4 OC3 LED2=!LED2; //LED3=!LED3; delay_ms(300); } } }这段代码问题如下:declaration may not appear after executable statement inblock,TIM OCINITTYPEDEF TIM OCINITSTRUCTURE,请修改这个问题
时间: 2024-04-06 07:29:04 浏览: 110
这个错误是因为在 `while` 循环中,变量 `TIM_OCInitStructure` 的声明出现在了可执行语句之后。这是不允许的,因为C语言规定变量声明必须在可执行语句之前。
要解决这个问题,你需要将变量 `TIM_OCInitStructure` 的声明语句移到可执行语句之前,或者将可执行语句移到声明语句之后。例如:
```
while(1)
{
TIM_OCInitTypeDef TIM_OCInitStructure; // 变量声明放在可执行语句之前
u16 u16tmp;
u16tmp += 500;
if(u16tmp > 10000) u16tmp=0;
TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1;
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_Low;
TIM_OCInitStructure.TIM_Pulse = u16tmp;
TIM_OC3Init(TIM4, &TIM_OCInitStructure);
LED2=!LED2;
delay_ms(300);
}
```
另外,你的代码中有一些重复的语句,比如 `delay_init()` 和 `NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2)`,可以将它们删除掉。
阅读全文