首先主函数如下:

#include "reg52.h"
#include "uart.h"

typedef unsigned int u16;
typedef unsigned char u8;

void main()
{
	UartInit();
	while(1);
}

uart.h文件:

#ifndef __UART_H
#define __UART_H

typedef unsigned int u16;
typedef unsigned char u8;

void UartInit();






#endif

编译后的现象:

Rebuild started: Project: Usart1
Rebuild target 'Target 1'
compiling main.c...
main.c(4): error C141: syntax error near 'u16', expected 'hdata'
main.c(5): error C231: 'u8': redefinition
compiling uart.c...
Target not created.
Build Time Elapsed:  00:00:00

        编译后出现以上问题,找了半天,把uart.h中的下面这两句放到uart.c中就没问题了,具体什么原因,还不知道。

typedef unsigned int u16;
typedef unsigned char u8;

修改后的uart.h如下:

#ifndef __UART_H
#define __UART_H



void UartInit();






#endif

Logo

腾讯云面向开发者汇聚海量精品云计算使用和开发经验,营造开放的云计算技术生态圈。

更多推荐