回复【13楼】Badu_Space:
---------------------------------
通了。老师看看我的分页函数,我没有用您的。
//分页写数据
[mw_shl_code=c,true]unsigned char I2C_Write_Eeprom( unsigned int Page, unsigned char offset, unsigned char *IIC_Buf, unsigned char Len )
{
//union B16_B08 Addr;
unsigned char xDevi_Addr,result;
unsigned char BufA[PAGE_SIZE];
unsigned char h, n;
// Addr.B16=Page*PAGE_SIZE+offset;
if( Page == 0x8025 ) xDevi_Addr = 0x64;
else xDevi_Addr = 0xa0;
if( (Page >= 0x200) && (Page != 0x8025) ) return 1;
h = Len;
memcpy( BufA, IIC_Buf, Len );
if( (offset+h)>  AGE_SIZE ) return 1; //
IIC_Start();//开始
if( Page == 0x8025 ) //时钟芯片
{
result = IIC_Write_Byte( xDevi_Addr ); //发送器件地址
if( result == 0 ) return 2; //failure.
result = IIC_Write_Byte( offset ); //发送子地址
if( result == 0 ) return 2; //failure.
for(n=0;n<h;n++)
{
result=IIC_Write_Byte(BufA[n]);
if(result==0) return 3;
}
}
else
{
EEPROM_Write_nByte(xDevi_Addr,Page*PAGE_SIZE+offset,IIC_Buf,Len); //函数内部没有动[/mw_shl_code]
[mw_shl_code=c,true]}
IIC_Stop();
return 0;//ok
}
//分页读数据
unsigned char I2C_Read_Eeprom( unsigned int Page, unsigned char offset, unsigned char *IIC_Buf, unsigned char Len )
{
unsigned char h, n, result,xDevi_Addr;
unsigned char BufA[PAGE_SIZE];
h = Len;
if( Page >< 0x0a ) h = h + 2; //
if( (offset+h)>  AGE_SIZE ) return 1; //地址溢出
if( (Page >= 0x200) && (Page != 0x8025) ) return 1; //地址溢出
if( Page == 0x8025 ) xDevi_Addr = 0x64;
else xDevi_Addr = 0xa0;
memcpy( BufA, IIC_Buf, Len );
IIC_Start();//开始
if( Page == 0x8025 ) //时钟芯片
{
result = IIC_Write_Byte( xDevi_Addr ); //发送器件地址
if( result == 0 ) return 2; //failure.
result = IIC_Write_Byte( offset ); //发送子地址
if( result == 0 ) return 2; //failure.
for(n=0;n<h;n++)
{
BufA[n]=IIC_Read_Byte();
if(n == (h - 1)) IIC_Ack(0x01); //
else IIC_Ack(0x00); //
}
}
else //24C512
{
EEPROM_Read_Page(xDevi_Addr,Page*PAGE_SIZE+offset,IIC_Buf,Len); //函数内部没动
}
IIC_Stop();
return 0;//ok
}>[/mw_shl_code]
|