#include "myiic.h"
#include "delay.h"
void Delayus(u16 us)
{
u16 i;
for(i=0;i250)
{
IIC_Stop();
return 1;
}
}
SCL_0//ʱÖÓÊä³ö0
return 0;
}
void IIC_Ack(void)
{
SDA_OUT();
SDA_0;
Delayus(10);
SCL_1
Delayus(10);
SCL_0
Delayus(10);
}
void IIC_NAck(void)
{
SDA_OUT();
SDA_1;
Delayus(10);
SCL_1
Delayus(10);
SCL_0
Delayus(10);
}
void IIC_Send_Byte(u8 txd)
{
u8 i;
SDA_OUT();
for(i=0;i<8;i++)
{
if(txd & 0x80) SDA_1
else SDA_0
txd <<= 1;
Delayus(10);
SCL_1
Delayus(10);
SCL_0
}
Delayus(10);
SCL_1
Delayus(10);
SCL_0
}
u8 IIC_Read_Byte(unsigned char ack)
{
u8 i,receive=0;
SDA_IN();//SDAÉèÖÃΪÊäÈë
for(i=0;i<8;i++)
{
SCL_1
Delayus(10);
receive <<=1;
if(READ_SDA) receive |= 0x01;
SCL_0
Delayus(10);
}
SDA_OUT();
return receive;
}
void R8025AC_Read(u8 sadd, u8 *buf, u8 len)
{
u8 i;
IIC_Start();
IIC_Send_Byte(0x64);
IIC_Send_Byte(sadd<<4|0x01);
IIC_Start();
IIC_Send_Byte(0x65);
for(i=0;i