-
Notifications
You must be signed in to change notification settings - Fork 0
/
ds18b20main.c
37 lines (30 loc) · 992 Bytes
/
ds18b20main.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
/* ds18b20main.c -- sample temperature using 1-Wire temperature sensor */
/* Copyright (c) 2020 Renaud Fivet */
#include <stdio.h>
#include "system.h" /* uptime */
#include "ds18b20.h" /* ds18b20_() */
int main( void) {
unsigned last = 0 ;
ds18b20_init() ;
ds18b20_resolution( 12) ; /* Set highest resolution: 12 bits */
ds18b20_convert() ; /* start temperature conversion */
for( ;;)
if( last == uptime)
yield() ;
else {
short val ;
last = uptime ;
switch( ds18b20_fetch( &val)) {
case DS18B20_SUCCESS:
printf( "%i.%i\n", val / 10, val % 10) ;
break ;
case DS18B20_FAIL_TOUT:
puts( "Timeout") ;
break ;
case DS18B20_FAIL_CRC:
puts( "CRC Error") ;
}
ds18b20_convert() ; /* start temperature conversion */
}
}
/* end of ds18b20main.c */