//-------------------24c04-.C-----------------------------------------------//名称:24C04I2C程序//------------------------------------------------------------------------...
//-------------------24c04-.C-----------------------------------------------
//名称: 24C04 I2C程序
//---------------------------------------------------------------------------
#define INT8U unsigned char
#define INT16U unsigned int
#include <reg51.h>
#include <intrins.h>
sbit SCL=P3^2;
sbit SDA=P3^3;
#include"I2C.h"
void Write_IIC(INT8U Dev_Addr,INT16U mem_addr,INT8U dat)
{
IIC_Start();
if(mem_addr < 0x0100) IIC_WriteByte(Dev_Addr);
else IIC_WriteByte(Dev_Addr | 0x02);
IIC_WriteByte(mem_addr);
IIC_WriteByte(dat);
IIC_Stop();
}
INT8U Random_Read(INT8U Dev_Addr,INT16U mem_addr)
{
INT8U d;
IIC_Start();
if(mem_addr<0x0100) IIC_WriteByte(Dev_Addr);
else IIC_WriteByte(Dev_Addr | 0x02);
IIC_WriteByte(mem_addr);
IIC_Start();
if(mem_addr<0x0100) IIC_WriteByte(Dev_Addr | 0x01);
else IIC_WriteByte(Dev_Addr | 0x03);
d=IIC_ReadByte(); IIC_NAck(); IIC_Stop();
return d;
}