请问大神我的ds1624程序芯片为什么不行

2019-07-16 04:21发布

#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;elsei_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();}}

友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。