#define IIC_Start() TWCR =(1<
/*=========================================
IicWrite(uchar ad,uchar da):ad=寄存器地址,da=数据;
IicRead(uchar ad): ad=寄存器地址
=========================================*/
void IicWrite(uchar ad,uchar da)
{
IIC_Start();
IIC_Wait();
TWDR=0xA2;//从机地址
IIC_Ack();
IIC_Wait();
TWDR=ad;
IIC_Ack();
IIC_Wait();
TWDR=da;
IIC_Ack();
IIC_Wait();
IIC_Stop();
}
uchar IicRead(uchar ad)
{
unsigned char data;
IIC_Start();
IIC_Wait();
TWDR = 0xA2;//从机地址
IIC_Ack();
IIC_Wait();
TWDR = ad;
IIC_Ack();
IIC_Wait();
IIC_Start();
IIC_Wait();
TWDR = 0xA3;
IIC_Ack();
IIC_Wait();
IIC_NoneAck();
IIC_Wait();
data=TWDR;
IIC_Stop();
return data;
}
单片机作业在IIC作业在主机方法下,对从机读取数据及写入数据.现已调试经过.期望我们可以弥补完善.