请问大神我的ds1624程序芯片为什么不行
#include<reg52.h>
#include<intrins.h>
#include"ds1624.h"
#include"LCD.h"
extern flag,h_tem,l_tem;
void delay(void)
{
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
}
void scl()
{
i_scl = 0;
delay();
i_scl = 1;
delay();
i_scl = 0;
delay();
}
void i_start() //I2C开始通信
{
i_scl = 1;
delay();
i_sda = 1;
delay();
i_sda = 0;
delay();
}
void i_stop() //I2C结束通信
{
i_scl = 1;
delay();
i_sda = 0;
delay();
i_sda = 1;
delay();
}
/* 向从机发送数据和应答信号
**
*/
bit send_i_dat(uchar dat)
{
uchar date,i;
date = dat;
i_scl = 0;
delay();
for(i = 0;i<8;i++)
{
if(date&0x80)
i_sda = 1;
else
i_sda = 0;
i_scl = 1;
delay();
date = date<<1;
i_scl = 0;
delay();
}
i_sda = 1; //释放总线
i_scl = 0;
return ~i_ack(); //检测应答
}
/*应答函数 sda为低表示应答 高为非应答
*/
uchar i_ack()
{
bit ack;
i_scl = 1;
delay();
ack = i_sda;
delay();
delay_1(1);
i_scl = 0;
delay();
return ack;
}
void send_ack(bit c)
{
//i_sda = 0;
i_scl = 0;
delay();
i_sda = c;
delay();
i_scl = 1;
delay();
}
uchar i_receive(bit b)
{
uchar i,r_dat = 0,j; //接收的数据
i_sda = 1;
delay();
i_scl = 1;
delay();
for(i = 0;i<8;i++)
{
j = i_sda;
_nop_();
_nop_();
r_dat = r_dat<<1;
i_scl = 0;
delay();
r_dat |= j;
i_scl = 1;
delay();
}
i_sda =1; //释放总线
delay();
send_ack(b);
//i_scl = 0;
//delay();
return r_dat;
}
uchar start_temperature()
{
i_start();
if(send_i_dat(0x90))
{
delay();
if(send_i_dat(0xee))
{
delay();
i_stop();
return 1;
}
else
{
i_stop();
return 0;
}
}
else
{
i_stop();
return 0;
}
}
uchar read_temperature()
{
i_start();
if(send_i_dat(0x90))
{
delay();
if(send_i_dat(0xaa))
{
delay();
i_start();
if(send_i_dat(0x91))
{
h_tem = i_receive(0);
delay();
l_tem=i_receive(1);
i_stop();
delay();
return(1);
}
}
}
else
{
i_stop();
delay();
return(0);
}
}
下面是我的主程序
i_scl = 0;
i_stop();
while(1)
{
start_temperature();
delay();
if(flag == 1) //已经到达1s
{
flag = 0;
read_temperature();
xs_ad();
dat_transform();
}
}
请把问题写清楚那里不行,如果问题是什么都不知道,那肯定是你的代码有问题,代码重新写好了
问题是我堵回来的数据是错的 和那个芯片没关系。我就是不知道程序错在哪里 或者是说I2C的时序有错了
