keil报错C267,请帮我看下列代码哪里出了问题.#include <REGX52.H> #include "I2C.h" #define AT24C02_ADDRESS 0xA0 /** * @brief AT24C02写入一个字节 * @param WordAddress 要写入字节的地址 * @param Data 要写入的数据 * @retval 无 */ void AT24C02_WriteByte(unsigned char WordAddress,Data) { I2C_Start(); I2C_SendByte(AT24C02_ADDRESS); I2C_ReceiveAck(); I2C_SendByte(WordAddress); I2C_ReceiveAck(); I2C_SendByte(Data); I2C_ReceiveAck(); I2C_Stop(); } /** * @brief AT24C02读取一个字节 * @param WordAddress 要读出字节的地址 * @retval 读出的数据 */ unsigned char AT24C02_ReadByte(unsigned char WordAddress) { unsigned char Data; I2C_Start(); I2C_SendByte(AT24C02_ADDRESS); I2C_ReceiveAck(); I2C_SendByte(WordAddress); I2C_ReceiveAck(); I2C_Start(); I2C_SendByte(AT24C02_ADDRESS|0x01); I2C_ReceiveAck(); Data=I2C_ReceiveByte(); I2C_SendAck(1); I2C_Stop(); return Data; }
时间: 2023-07-16 22:12:08 浏览: 143
keil经常出现错误
在函数AT24C02_WriteByte(unsigned char WordAddress,Data) 中,参数Data没有指定数据类型,应该为:
void AT24C02_WriteByte(unsigned char WordAddress, unsigned char Data)
另外,在函数AT24C02_ReadByte(unsigned char WordAddress)中,应该在I2C_SendByte(AT24C02_ADDRESS|0x01);语句后加上I2C_ReceiveAck();语句,即:
I2C_SendByte(AT24C02_ADDRESS|0x01);
I2C_ReceiveAck();
这是因为在读取数据时,需要发送一个读命令,然后才能接收数据,需要先接收应答信号。
阅读全文