uchar ds_date; dsas=1; dsds=1; dsrw=1; dscs=0; P0=add; dsas=0; dsds=0; P0=0xff; ds_date=P0; dsds=1; dsas=1; dscs=1; return ds_date;
}
void set_time(uchar a,uchar b,uchar c,uchar d,uchar f,uchar g,uchar h) { write_ds(0,a); write_ds(2,b);
write_ds(4,c); write_ds(6,d); write_ds(7,f); write_ds(8,g); write_ds(9,h);
}
void set_alarm(uchar ashi,uchar afen,uchar amiao) { write_ds(1,amiao); write_ds(3,afen); write_ds(5,ashi);
}
57
void delay_18b20(unsigned int i) {
while(i--); }
void Init_DS18B20() {
unsigned char x=0; DQ = 1; delay_18b20(8); DQ = 0; delay_18b20(80); DQ = 1; delay_18b20(10); x=DQ; delay_18b20(5); }
unsigned char ReadOneChar() {
unsigned char i=0; unsigned char dat = 0; for (i=8;i>0;i--) {
DQ = 0; dat>>=1; DQ = 1; if(DQ) dat|=0x80; delay_18b20(5); } return(dat); }
void WriteOneChar(unsigned char dat) {
58
unsigned char i=0; for (i=8; i>0; i--) { DQ = 0; DQ = dat&0x01; delay_18b20(5); DQ = 1; dat>>=1; }
delay_18b20(5); }
unsigned char ReadTemperature() {
unsigned char a=0; unsigned char b=0; unsigned char t=0; float tt=0; Init_DS18B20(); WriteOneChar(0xCC); WriteOneChar(0x44); delay_18b20(200); Init_DS18B20(); WriteOneChar(0xCC); WriteOneChar(0xBE); a=ReadOneChar(); b=ReadOneChar(); b<<=4;
b+=(a&0xf0)>>4; t=b; return (t); }
void delay2(uint z) {
59
}
uint x,y; for(x=z;x>0;x--)
for(y=110;y>0;y--);
60