在头文件的声明中,不可重复的包含一个文件如下,I2C.h文件与LCD.h文件就会产生冲突,因为都包含了头文件reg52.h
(1)I2C.h头文件的定义:
#ifndef _I2C_H_
#define _I2C_H_
#include <reg52.h>
//定义I2C总线时钟的延时值,要根据实际情况修改,取值1~255
//SCL信号周期约为(I2C_DELAY_VALUE*4+15)个机器周期
#define I2C_DELAY_VALUE 12
//定义I2C总线停止后在下一次开始之前的等待时间,取值1~65535
//等待时间约为(I2C_STOP_WAIT_VALUE*8)个机器周期
//对于多数器件取值为1即可;但对于某些器件来说,较长的延时是必须的
#define I2C_STOP_WAIT_VALUE 120
//I2C总线初始化,使总线处于空闲状态
void I2C_Init();
void I2C_Init1();
void I2C_Init2();
void I2C_Init3();
//I2C总线综合发送函数,向从机发送多个字节的数据
bit I2C_Puts
(
unsigned char SlaveAddr,
unsigned int SubAddr,
unsigned char SubMod,
char *dat,
unsigned int Size
);
bit I2C_Puts1
(
unsigned char SlaveAddr,
unsigned int SubAddr,
unsigned char SubMod,
char *dat,
unsigned int Size
);
bit I2C_Puts2
(
unsigned char SlaveAddr,
unsigned int SubAddr,
unsigned char SubMod,
char *dat,
unsigned int Size
);
bit I2C_Puts3
(
unsigned char SlaveAddr,
unsigned int SubAddr,
unsigned char SubMod,
char *dat,
unsigned int Size
);
//I2C总线综合接收函数,从从机接收多个字节的数据
bit I2C_Gets
(
unsigned char SlaveAddr,
unsigned int SubAddr,
unsigned char SubMod,
char *dat,
unsigned int Size
);
bit I2C_Gets1
(
unsigned char SlaveAddr,
unsigned int SubAddr,
unsigned char SubMod,
char *dat,
unsigned int Size
);
bit I2C_Gets2
(
unsigned char SlaveAddr,
unsigned int SubAddr,
unsigned char SubMod,
char *dat,
unsigned int Size
);
bit I2C_Gets3
(
unsigned char SlaveAddr,
unsigned int SubAddr,
unsigned char SubMod,
char *dat,
unsigned int Size
);
#endif //_I2C_H_
(2)LCD.h头文件的定义:
#ifndef _LCD_H_
#include<intrins.h>
#include <reg52.h>
#include <absacc.h>
#include <ctype.h>
#define Uchar unsigned char
#define Uint unsigned int
#define Busy 0x80 // 忙判别位
void Checkbusy1(); //读取忙标志函数
void Checkbusy2();
void LcdWriteCommand1( Uchar CMD1,Uchar AttribC1); //写控制字
void LcdWriteCommand2( Uchar CMD2,Uchar AttribC2);
void LcdWriteData1( char dataW1); //写数据
void LcdWriteData2( char dataW2);
void LocateXY1( char posx1,char posy1); //显示光标定位
void LocateXY2( char posx2,char posy2);
void DispOneChar1(Uchar x1,Uchar y1,Uchar Wdata1); //在光标指定位置写一字符
void DispOneChar2(Uchar x2,Uchar y2,Uchar Wdata2);
void ePutstr1(Uchar x1,Uchar y1, Uchar code *ptr1); //在光标指定位置开始写字符串
void ePutstr2(Uchar x2,Uchar y2, Uchar code *ptr2);
void setCGRAM2(void); //设置CGRAM地址
void displaydata2(void); //显示年月日
void LcdReset1( void );
void LcdReset2( void );
void Delay(unsigned int t);
#endif
当然在每个对应的.C文件都用到了C51中的reg52的特殊寄存器,如P1,P2。两个文件在主程序中都要用到,既在主程序中要包含两个头文件,I2C.h,LCD.h。此时会提示出错。
可将LCD.h中的第三行改为#include <I2C.h>,这样就解决了同时包含 reg52.h的问题。
用户137104 2008-12-26 17:28
dmu_xw 2008-12-20 09:56
用户1353726 2008-12-17 22:44