Line 33... |
Line 33... |
33 |
} |
33 |
} |
34 |
|
34 |
|
35 |
|
35 |
|
36 |
float ds1820_read() |
36 |
float ds1820_read() |
37 |
{ |
37 |
{ |
38 |
unsigned int1 busy=0; |
38 |
unsigned int1 ready=0; |
39 |
int8 SN[10]; |
39 |
int8 SN[10]; |
40 |
unsigned int8 n; |
40 |
unsigned int8 n; |
41 |
float result; |
41 |
float result; |
42 |
|
42 |
|
43 |
onewire_reset(); |
43 |
onewire_reset(); |
44 |
onewire_write(0xCC); |
44 |
onewire_write(0xCC); |
45 |
onewire_write(0x44); |
45 |
onewire_write(0x44); |
46 |
|
46 |
|
- |
|
47 |
for(n=0;n<200;n++) // wait until sensor is busy or timeout will be over |
- |
|
48 |
{ |
47 |
while (busy == 0) busy = onewire_read(); |
49 |
ready = onewire_read(); |
- |
|
50 |
if(ready == TRUE) break; |
- |
|
51 |
delay_ms(1); |
- |
|
52 |
} |
48 |
|
53 |
|
49 |
onewire_reset(); |
54 |
onewire_reset(); |
50 |
onewire_write(0xCC); |
55 |
onewire_write(0xCC); |
51 |
onewire_write(0xBE); |
56 |
onewire_write(0xBE); |
52 |
|
57 |
|
Line 56... |
Line 61... |
56 |
result=make16(SN[1],SN[0]); |
61 |
result=make16(SN[1],SN[0]); |
57 |
result=result*6+result/4; // 1bit = 0,0625gradC recalculate to 1/100gradC |
62 |
result=result*6+result/4; // 1bit = 0,0625gradC recalculate to 1/100gradC |
58 |
} |
63 |
} |
59 |
else |
64 |
else |
60 |
{ |
65 |
{ |
61 |
result=-273.15; |
66 |
result=-27315; |
62 |
} |
67 |
} |
63 |
return(result); |
68 |
return(result); |
64 |
} |
69 |
} |