|
/*******************************************************************************
* 函数名 : void At24c02Write(unsigned char addr,unsigned char dat)
* 函数功能 : 往24c02的一个地址写入一个数据
* 输入 : 无
* 输出 : 无
*******************************************************************************/
void At24c02Write(unsigned int addr, unsigned char dat)
{
I2cStart();
I2cSendByte(0xa6);//发送写器件地址
I2cSendByte(addr>>8);//发送要写入内存地址
I2cSendByte(addr&0xff);//发送要写入内存地址
// I2cSendByte(dat<<8); //发送数据
//I2cSendByte(addL);//发送要写入内存地址
I2cSendByte(dat); //发送数据
I2cStop();
}
/*******************************************************************************
* 函数名 : unsigned char At24c02Read(unsigned char addr)
* 函数功能 : 读取24c02的一个地址的一个数据
* 输入 : 无
* 输出 : 无
*******************************************************************************/
unsigned char At24c02Read(unsigned int addr)
{
unsigned char num;
I2cStart();
I2cSendByte(0xa6); //发送写器件地址
I2cSendByte(addr>>8); //发送要读取的高八位地址
I2cSendByte(addr&0xff); //发送要读取低八位的地址
// I2cSendByte(addL); //发送要读取的地址
I2cStart();
I2cSendByte(0xa7); //发送读器件地址
num=I2cReadByte(); //读取数据
// num=num<<8|I2cReadByte(); //读取数据
I2cStop();
return num;
}
void write_m_data_24c64(u16 addr,u8 *m_data_24c64,u8 n) //从某地址开始连续多字节写入
{
u8 i;
I2cStart();
I2cSendByte(0xa6);//发送写器件地址
I2cSendByte(addr>>8);//发送要写入内存地址
I2cSendByte(addr&0xff);//发送要写入内存地址
for(i=0; i<n; i++)
{
I2cSendByte(*(m_data_24c64++));//写储存数据
Delay10us();
}
I2cStop();
}
void read_m_data_24c64(u16 addr,u8 n)//从某地址开始连续读取n个数据
{
u8 i;
for(i=0;i<n;i++)
{
I2cStart();
I2cSendByte(0xa6); //发送写器件地址
I2cSendByte(addr>>8); //发送要读取的高八位地址
I2cSendByte(addr&0xff); //发送要读取低八位的地址
addr++;
I2cStart();
I2cSendByte(0xa7); //发送读器件地址
receive[i]= I2cReadByte();
Delay10us();
I2cStop();
}
}
对于单字节相当于页写,普通的是8位数据,这个传递是32位的数据
|
-
-
程序.zip
71.89 KB, 下载次数: 4, 下载积分: 黑币 -5
|