首先主函数如下:
#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