#include <REGX52.H>
#include <I2C.h>
#define SLAVE_ADDRESS 0xA0
/**
* @brief: 发送字节数据
* @param: 字地址
* @param: 数据
* @retval:
* @author: Rukawa
* @date: 2024-03-19 00:27:47
**/
void AT24C02_sendByte(unsigned char wordAddress, unsigned char content)
{
I2C_start();
I2C_sendByte(SLAVE_ADDRESS);
I2C_receiveAck();
I2C_sendByte(wordAddress);
I2C_receiveAck();
I2C_sendByte(content);
I2C_receiveAck();
I2C_stop();
}
/**
* @brief: 接收字节数据
* @param: 字地址
* @retval: 数据
* @author: Rukawa
* @date: 2024-03-19 00:28:23
**/
unsigned char AT24C02_receiveByte(unsigned char wordAddress){
unsigned char result = 0;
I2C_start();
I2C_sendByte(SLAVE_ADDRESS);
I2C_receiveAck();
I2C_sendByte(wordAddress);
I2C_receiveAck();
I2C_start();
I2C_sendByte(SLAVE_ADDRESS | 1);
I2C_receiveAck();
result = I2C_receiveByte();
I2C_sendAck(1); // 不给1会有问题
I2C_stop();
return result;
}
08-07
07-13