-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathds18s20.c
47 lines (37 loc) · 1.02 KB
/
ds18s20.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include "ds18s20.h"
owByte ow_DS18S20_init() {
ow_init();
return ow_reset();
}
owByte ow_DS18S20_startTempConvAll() {
if(ow_reset()) {
ow_writeByte(DS18S20_SKIP_ROM);
ow_writeByte(DS18S20_START_TEMP_CONV);
return OW_TRUE;
}
return OW_FALSE;
}
float ow_DS1820_getTemp(owByte lsb, owByte msb) {
if(msb == 0) { // Nombre positif, on divise par 2 pour obtenir la partie décimal
return lsb >> 1;
} else { // Nombre négatif : décodage du complément à 2 et division par 2
return -(256 - lsb) >> 1;
}
}
owByte ow_DS1820_readScratchPad(owByte* owPAD) {
owByte i;
if(ow_reset()) {
ow_writeByte(DS18S20_SKIP_ROM);
ow_writeByte(DS18S20_READ_SCRATCHPAD);
for(i=0; i<DS18S20_SCRATCHPAD_SIZE; i++)
owPAD[i] = ow_readByte();
return OW_TRUE;
}
return OW_FALSE;
}
void ow_readROM(owByte* owROM) {
owByte i;
ow_reset();
ow_writeByte(DS18S20_READ_ROM);
for(i=0; i<8 ; i++) owROM[i] = ow_readByte();
}