uchar qian=0,bai=0,shi=0,ge=0; uint temp; // variable of temperature
void delay2(uchar x); //x\*0.14MS void dsreset(void); //send reset and initialization command bit tmpreadbit(void); //read a bit uchar tmpread(void); //read a byte date void tmpwritebyte(uchar dat); //write a byte to ds18b20 void tmpchange(void); //DS18B20 begin change uint tmp(); //get the temperature void fenli(uint temp); //分离温度函数 void display(uchar qian,uchar bai,uchar shi,uchar ge);//显示函数 //共阳数码管 uchar code table[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e,0x7f};
void tmpchange(void) //DS18B20 begin change { dsreset(); delay2(1); tmpwritebyte(0xcc); // address all drivers on bus tmpwritebyte(0x44); // initiates a single temperature conversion }
uint tmp() //get the temperature { float tt; uchar a,b; dsreset(); delay2(1); tmpwritebyte(0xcc); tmpwritebyte(0xbe); a=tmpread(); //低字节 b=tmpread(); //高字节 temp=b; temp<<=8; //two byte compose a int variable temp=temp|a; tt=temp\*0.0625; temp=tt\*10+0.5; //0.5四舍五入作 return temp; }