uchar R_word;
uchar ACK_Flag;
uchar read_buffer_iic[16];
uchar write_buffer_iic[16];
void Start(void)
{
TSDA_IO_OUT();
TSCL_IO_OUT();
TSDA=1;
TSCL=1;delay_us(10);
TSDA=0;delay_us(10);
TSCL=0;
delay_us(10);
}
void Stop(void)
{
TSDA_IO_OUT();
TSCL_IO_OUT();
TSDA=0;
TSCL=0;delay_us(10);
TSCL=1;delay_us(10);
TSDA=1;
}
void Send_Byte(uchar Byte)
{
uint i;
TSDA_IO_OUT();
TSCL_IO_OUT();
TSCL=0;
delay_us(10);
for (i=0;i<8;i++)
{
if(Byte 0x80)
{TSDA=1;}
else
{TSDA=0;}
Byte = Byte << 1;
delay_us(10);
TSCL=1;
delay_us(10);
TSCL=0;
delay_us(10);
}
}
void ACK(void)
{
TSCL_IO_OUT();
TSDA_IO_IN();
TSDA=1;
TSCL=1;delay_us(5);
ACK_Flag = 0;
if((RTSDA ))
ACK_Flag = 1;
TSCL=0;
delay_us(10);
}
void ACK_0(void)
{
TSCL_IO_OUT();
TSDA_IO_OUT();
TSDA=0;
TSCL=0;
delay_us(10);
TSCL=1;
delay_us(10);
TSCL=0;
delay_us(10);
}
void NOACK(void)
{
TSCL_IO_OUT();
TSDA_IO_OUT();
TSDA=1;
TSCL=0;
delay_us(10);
TSCL=1;
delay_us(10);
TSCL=0;
delay_us(10);
}
void Receive_Byte(void)
{
uint j;
R_word = 0x00;
TSDA_IO_IN();
TSCL_IO_OUT();
delay_us(10);
for(j=0;j<8;j++)
{
R_word = R_word << 1;
TSCL=0;
delay_us(10);
if((RTSDA))
R_word+=1;
delay_us(10);
TSCL=1;
delay_us(10);
}
}
void I2C_75_write(uchar W_addruchar dat)
{
delay_us(10);
Start();
Send_Byte(0x90);
ACK();
Send_Byte(W_addr);
ACK();
Send_Byte(dat);
ACK();
Stop();
}
void I2C_75_Read(uint R_addruchar n)
{
uchar i=0;
Start();
Send_Byte(0x90);
ACK();
Send_Byte(R_addr);
ACK();
Start();
Send_Byte(0x91);
ACK();
Receive_Byte();
ACK_0();
read_buffer_iic[0] = R_word ;
Receive_Byte();ACK_0();
read_buffer_iic[1] = R_word ;
NOACK();
Stop();
}
//读取温度并处理数据
void readTEMP(void)
{
I2C_75_write(0x010x00);
I2C_75_Read(02);
delay_us(10);
tempH=read_buffer_iic[0];
if((tempH 0x80)==0x80)
{
tempH-=0x01;
tempH=~tempH;
zhengfuflag=1;
}
//temp= read_buffer_iic[0] + (uint)(read_buffer_iic[1]*0.0625*0.0625);
temprd= (float)tempH+ (float)(((read_buffer_iic[1]>>4) 0x0f)*0.0625);
if(zhengfuflag==1){floattohex(0-temprd);}//