IIC模拟:
bit WriteNByte(unsigned int sla,unsigned int suba,unsigned int *s,unsigned int n)
{
unsigned int i;
I2C_Start();//启动I2C
SendData(sla);//发送器件地址
Test_Ack();
if(i2c_flag==0)
return(0);
SendData(suba);
Test_Ack();
if(i2c_flag==0)
return(0);
for(i=0;i
{
SendData(*(s+i));
Test_Ack();
if(i2c_flag==0)
return(0);
}
I2C_Stop();
return(1);
}
bit ReadNByte(unsigned int sla,unsigned int suba,unsigned int *p,unsigned int n)
{
unsigned int i;
I2C_Start();//启动I2C
SendData(sla);//发送器件地址
Test_Ack();
//if(i2c_flag==0) return(0);
SendData(suba);//发送器件内部地址
Test_Ack();
//if(i2c_flag==0) return(0);