//#define _HC_EEPROM 是否为双字节地址
#define MAX_ONE_PAGE 0x0f 一页的最大地址尾数
#define MAX_ADDRESS 0x0f 最大地址
void I2cPageWrite(unsigned int Address,unsigned int Length,unsigned char *Data_Handle)
{
if(Length>(MAX_ADDRESS-Address+1))
{
I2c_State=NO_ENOUGH_ROM;
}
else
{
while(Length>0)
{
I2c_State=I2C_WRITTING;
I2cStart();
I2cSend(I2C_WRITE_COMMAND);
#ifdef _HC_EEPROM
I2cSend((unsigned char)(Address/256));
#endif
I2cSend((unsigned char)(Address%256));
do
{
I2cSend(*Data_Handle);
Length--;
Data_Handle++;
Address++;
}while(((Address&MAX_ONE_PAGE)!=0)&&(Length>0));
I2cStop();
I2cDelay();
}
I2c_State=I2C_WRITE_OVER;
}
}
void I2cPageRead(unsigned int Address,unsigned int Length,unsigned char *Data_Handle)
{
if(Length>(MAX_ADDRESS-Address+1))
{
I2c_State=OVER_MAX_ROM;
}
else
{
while(Length>0)
{
I2c_State=I2C_READING;
I2cStart();
I2cSend(I2C_WRITE_COMMAND);
#ifdef _HC_EEPROM
I2cSend((unsigned char)(Address/256));
#endif
I2cSend((unsigned char)(Address%256));
I2cStart();
I2cSend(I2C_READ_COMMAND);
do
{
*Data_Handle=I2cRead();
Length--;
Data_Handle++;
Address++;
if(((Address&MAX_ONE_PAGE)!=0)&&(Length>0))
I2cAck();
else
I2cNoAck();
}while(((Address&MAX_ONE_PAGE)!=0)&&(Length>0));
I2cStop();
}
I2c_State=I2C_READ_OVER;
}
}
|