|
发表于 2013-12-18 11:56:47
|
显示全部楼层
void read_mul_memory(u16 ReadAddr,u8 *rx_buf,u16 len)
{
u16 i=0;
IIC_Start();
IIC_Send_Byte(0XA0+((ReadAddr>>8)<<1));
IIC_Wait_Ack();
IIC_Send_Byte(ReadAddr%256);
IIC_Wait_Ack();
IIC_Start();
IIC_Send_Byte(0XA1);
IIC_Wait_Ack();
for(i=0;i<len;i++)
{
rx_buf[i]=IIC_Read_Byte();
if(len-i>1)
IIC_Ack();
else
IIC_NAck();
}
IIC_Stop();
}
void write_mul_memory(u16 WriteAddr, u8 *tx_buf, u16 len)
{
u8 i = 0;
u16 j=0;
if(len/16>0)
{
for(j=0;j<len/16;j++)
{
IIC_Start();
IIC_Send_Byte( 0XA0+((WriteAddr>>8)<<1));
IIC_Wait_Ack();
IIC_Send_Byte( WriteAddr%256+(j<<4));
IIC_Wait_Ack();
for( i=0;i<16;i++ )
{
IIC_Send_Byte( tx_buf[i+(j<<4)] );
IIC_Wait_Ack( );
}
IIC_Stop();
delay_us(5000);//5ms
}
}
if(len%16>0)
{
IIC_Start();
IIC_Send_Byte( 0XA0+((WriteAddr>>8)<<1));
IIC_Wait_Ack();
IIC_Send_Byte( WriteAddr%256+((len>>4)<<4) );
IIC_Wait_Ack();
for( i=0;i<len%16;i++ )
{
IIC_Send_Byte( tx_buf[i+((len>>4)<<4)] );
IIC_Wait_Ack( );
}
IIC_Stop();
delay_us(5000);//5ms
}
} |
|