#i n cl u de<reg52.h>#define uch ar u nsig ned c h a r#defi n e u int u n signed intsbi t DQ=P 1^4;//d s 18 b2 0 与单片机连接口unsigned c h a r c o de str[]={0x3f,0x06,0 x5b,0x4f,0x6 6,0x 6d,0x7d,0 x 07,0 x 7 f,0x6 f,0x3 9};//共阴数码管字码表unsi g ned char co d e st r1[]={0x0bf,0 x 8 6,0x0db,0 x 0 cf,0x 0 e6,0 x0 ed,0 x 0 fd,0x87,0x 0 f f,0 x0ef,0x39};//个位带小数点字码表un s ig ne d c har c od e w e i[]={0 x 0f e,0 x0 fd,0x0 f b,0x 0 f7};uc ha r data disdata[5];uint tva l ue;//温度值uchar tf l ag;//温度正负标志/******************************ds1 8 2 0程序***************************************/void de l ay_1 8B20(unsig n ed int i)//延时 1 微秒{ while(i--);}v o i d d s18 2 0 rst()/*d s1820 复位*/{ u n si gne d c h ar x=0;DQ = 1; //D Q复位de l a y_18B 2 0(4); //延时D Q = 0; //DQ拉低de la y_18 B20(100); //精确延时不小于4 80usDQ = 1; //拉高d elay_1 8 B 20(40); } u cha r ds 1 820rd()/*读数据*/{ unsigned c ha r i=0;u n sign e d ch a r dat = 0;for (i=8;i>0;i--){ D Q = 0; //给脉冲信号 d at>>=1; DQ = 1; //给脉冲信号 if(D Q) da t|=0x 8 0; delay_18B 2 0(10);} return(dat);}v o i d d s1820 w r(uch a r wdata)/*写数据*/{unsigne d ch a r i=0; for (i=8; i>0; i--) { DQ = 0; D Q = w dat a&0x01; d elay_18B20(10); DQ = 1; wdata>>=1; }}read_temp()/*读取温度值并转换*/{uchar a,b;ds1 820 rst();d s 18 2 0wr(0 x cc);//*跳过读序列号*/d s 1 820wr(0x4 4);//*启动温度转换*/d s18 20 r s t();d s1 82 0wr(0x c c);//*跳过读序列号*/ds1820 w r(0 xbe);//*读取温度*/a=ds18 2 0rd();b=d s18 2 0 ...