本人菜鸟,在编译main.c文件时发现报了四个错
先贴出原始程序和报错
main.c(12): error: #65: expected a ";"
main.c(38): warning: At end of source: #12-D: parsing restarts here after previous syntax error
main.c(38): error: At end of source: #130: expected a "{"
main.c(38): error: At end of source: #67: expected a "}"
main.c: 1 warning, 4 errors
#include "stm32f10x.h" // Device header
#include "delay.h"//使用延时函数
#include "timer.h"
void LED0_Init()
int main(void)
{
// OLED_Init();
LED0_Init();
Timer_Init();
while(1)
{
// GPIO_ResetBits(GPIOA,GPIO_Pin_0);//亮
};
}
void LED0_Init()
{
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,ENABLE);
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Pin=GPIO_Pin_0;
GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
GPIO_Init(GPIOA,&GPIO_InitStructure);
// GPIO_SetBits(GPIOA,GPIO_Pin_0);
}
在参考了别的文章中大佬的建议后查了别的文件,都没有漏并且很正常,我就想可能是不是就是main文件自己的问题,然后,在我改掉开头的声明后(只加了一个;)报错就只有一个了
void LED0_Init();
贴出此时的报错(warning因为个人原因有俩,不过另一个是没空行,很好解决)
main.c(28): error: #268: declaration may not appear after executable statement in block
GPIO_InitTypeDef GPIO_InitStructure;
main.c(7): warning: #1295-D: Deprecated declaration LED0_Init - give arg types
这件事告诉我,可能并不是其他文件的原因,可能原因就在本文件内,当然,本人C语言学艺不精,后知后觉,想起来可能是函数声明的问题,所列的warning在括号内补充void后消失了
贴出改好的main.c,此main文件并未使用C99mode,这和我看到大佬的示例有一定差别,但,不使用C99mode也避免了在原文下出现的换用C99mode报错的可能
#include "stm32f10x.h" // Device header
#include "delay.h"//使用延时函数
#include "timer.h"
void LED0_Init(void);
int main(void)
{
// OLED_Init();
LED0_Init();
Timer_Init();
while(1)
{
// GPIO_ResetBits(GPIOA,GPIO_Pin_0);//亮
};
}
void LED0_Init()
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,ENABLE);
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Pin=GPIO_Pin_0;
GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
GPIO_Init(GPIOA,&GPIO_InitStructure);
// GPIO_SetBits(GPIOA,GPIO_Pin_0);
}
总结:可以不使用C99mode,但要在开头声明函数(记得加;),可以把函数放在末尾