Line 1... |
Line 1... |
1 |
#include "1wire.c" |
1 |
#include "1wire.c" |
2 |
|
2 |
|
3 |
// compute CRC |
3 |
// compute CRC |
4 |
// *sn - pointer to the byte array |
4 |
// *sn - pointer to the byte array |
5 |
// num - length of array |
5 |
// num - length of array |
- |
|
6 |
|
6 |
inline int8 TM_check_CRC(unsigned int8 *sn, unsigned int8 num) |
7 |
int8 TM_check_CRC(unsigned int8 *sn, unsigned int8 num) |
7 |
{ |
8 |
{ |
8 |
// CRC table |
9 |
// CRC table |
9 |
const int8 TouchCRC[256]= { |
10 |
const int8 TouchCRC[256]= { |
10 |
0, 94, 188, 226, 97, 63, 221, 131, 194, 156, 126, 32, 163, 253, 31, 65, |
11 |
0, 94, 188, 226, 97, 63, 221, 131, 194, 156, 126, 32, 163, 253, 31, 65, |
11 |
157, 195, 33, 127, 252, 162, 64, 30, 95, 1, 227, 189, 62, 96, 130, 220, |
12 |
157, 195, 33, 127, 252, 162, 64, 30, 95, 1, 227, 189, 62, 96, 130, 220, |
Line 54... |
Line 55... |
54 |
onewire_reset(); |
55 |
onewire_reset(); |
55 |
onewire_write(0xCC); |
56 |
onewire_write(0xCC); |
56 |
onewire_write(0xBE); |
57 |
onewire_write(0xBE); |
57 |
|
58 |
|
58 |
for(n=0;n<9;n++) SN[n]=onewire_read(); |
59 |
for(n=0;n<9;n++) SN[n]=onewire_read(); |
59 |
if ((SN[8]==TM_check_CRC(SN,8))&&(SN[7]==0x10)) // Check CRC and family code to prevent O's error |
60 |
// if ((SN[8]==TM_check_CRC(SN,8))&&(SN[7]==0x10)) // Check CRC and family code to prevent O's error |
- |
|
61 |
if ((SN[7]==0x10)) // Check CRC and family code to prevent O's error |
60 |
{ |
62 |
{ |
61 |
result=make16(SN[1],SN[0]); |
63 |
result=make16(SN[1],SN[0]); |
62 |
result=result*6+result/4; // 1bit = 0,0625gradC recalculate to 1/100gradC |
64 |
result=result*6+result/4; // 1bit = 0,0625gradC recalculate to 1/100gradC |
63 |
} |
65 |
} |
64 |
else |
66 |
else |