I2C.c和I2C.h的导入
at24c02写数据
void at24c02_write(uint8_t *data,uint8_t address,uint8_t num);//向EEPROM写数据
void at24c02_read(uint8_t *data,uint8_t address,uint8_t num);//读数据EEPROM
//
void at24c02_write(uint8_t *data,uint8_t address,uint8_t num)
{
I2CStart();
I2CSendByte(0xa0);
I2CWaitAck();
I2CSendByte(address );
I2CWaitAck();
while(num--)//一次写入字节数
{
I2CSendByte(*data++ );
I2CWaitAck();
}
I2CStop();
delay1 (500);
}
at24c02读数据
在这里插入代码片
//
void at24c02_read(uint8_t *data,uint8_t address,uint8_t num)
{
I2CStart();
I2CSendByte(0xa0);
I2CWaitAck();
I2CSendByte(address );
I2CWaitAck();
I2CStart();
I2CSendByte(0xa1);
I2CWaitAck();
while(num--)
{
*data++=I2CReceiveByte();
if(num)
I2CSendAck();
else
I2CSendNotAck();
}
I2CStop();
}