多点式单总线数字温度监测系统(完整程序)(8)

2018-11-22 18:40

/******功能:复位脉冲**参数:bool ****/ bit resetpulse(void) { }

/******功能:ds18b20的初始化**参数:无 ****/ void ds18b20_init(void) { }

/******功能:向ds18b20写命令 **参数:无 ****/ void ds18b20_writecommand(uchar command) {

uchar i; for(i=0;i<8;i++) {

if((command & 0x01)==0) while(1) { }

if(!resetpulse()) //收到ds18b20的应答信号 { } else

resetpulse(); //否则再发复位信号 //printf(\//delay240us(); //延时240us DQ=1;

delay600us(); //延时240us break;

DQ=0;

delay600us(); DQ=1;

delay60us(); return(DQ);

// 延时60us

//读取P1.0的状态

//延时500us

16

}

}

{ } else { DQ=0; }

command=_cror_(command,1); // 右移1位

_nop_(); _nop_(); DQ=1;

delay60us(); _nop_(); _nop_(); _nop_(); _nop_();

//延时60us

//延时2us

//写1

DQ=0; _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); DQ=1; _nop_(); _nop_();

//写0 //延时60us

delay60us();

/******功能:读ds18b20数据 **参数:返回读到的数据****/ uchar ds18b20_readdata(void) {

uchar readdata; uchar i;

for(i=0;i<8;i++)

17

}

{ }

return readdata;

**参数:无返回****/

DQ=0; _nop_(); _nop_(); _nop_(); DQ=1;

//释放总线

注意不需要

//delay15us(); { } else { } if(i<7)

readdata=_cror_(readdata,1);

readdata=readdata|0x80; delay60us();

//读到的是1

readdata=readdata&0x7f; delay60us();

if(DQ==0) //如果读到的是0

/******功能:温度处理函数 {

uint temp1,temp2,temp3; if(high&0x80)//判断正负 { flag=1;

temp3=temp3|high; temp3=temp3&0x00ff; temp3=temp3<<8; temp1=temp3; temp1=temp1|low;

void temperature_process(uchar low,uchar high)

18

}

temp1=(temp1^0xffff); temp1=temp1+1; high=temp1>>4; } else { }

flag=0;

//zhen

temp1=high; temp2=low; temp1=temp1<<4; temp2=temp2>>4; temp3=temp1|temp2; high=temp3; low=low&0x0f; process(high,low); process(high,low);

//取反加1

low=temp1&0x000f;

/******功能:数值处理函数**参数:无返回****/ void process(unsigned char high,unsigned char low) {

uint temp1; uchar i; temp1=low*625;

xiaoshu_temp[0]=temp1/1000+'0'; //xiaoshu_temp[1]=temp1/100+'0'; //xiaoshu_temp[2]=temp10/10+'0'; //xiaoshu_temp[3]=temp1+'0'; xiaoshu_temp[1]='\\0'; dot_dis=1;

//if(xiaoshu_temp[3]=='0') //{

// xiaoshu_temp[3]='\\0';

19

}

// if(xiaoshu_temp[2]=='0') // // // // //

{ }

xiaoshu_temp[2]='\\0'; if(xiaoshu_temp[1]=='0') { }

xiaoshu_temp[1]='\\0'; if(xiaoshu_temp[0]=='0') { } else

dot_dis=1;

xiaoshu_temp[0]='\\0'; dot_dis=0;

//

// // }

zhen_temp[0]=high/100+'0'; zhen_temp[1]=high0/10+'0'; zhen_temp[2]=high+'0'; zhen_temp[3]='\\0'; for(i=0;i<2;i++)

if(zhen_temp[0]=='0')

{

zhen_temp[0]=zhen_temp[1]; zhen_temp[1]=zhen_temp[2]; zhen_temp[2]='\\0'; } break;

else

/****************************************/ //serial_set func void serial_set(void) {

20


多点式单总线数字温度监测系统(完整程序)(8).doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:案例分析

相关阅读
本类排行
× 注册会员免费下载(下载后可以自由复制和排版)

马上注册会员

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: