-
Notifications
You must be signed in to change notification settings - Fork 1
/
hello_dht.c
50 lines (41 loc) · 965 Bytes
/
hello_dht.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
48
49
50
#include <avr/io.h>
#include <util/delay.h>
#include "dbg_putchar.h"
#include "printf.h"
#include "dht11.h"
#include "vccmeasure.h"
#define TINUDHT_PIN PB3
void sleep(int millisec)
{
while(millisec) {
_delay_ms(1);/* 1 ms delay */
millisec--;
}
}
void serPutc(void *p, char c)
{
dbg_putchar(c);
}
int main(int argc, char *argv[])
{
TinuDHT tinudht;
uint8_t ret;
dbg_tx_init();
init_printf((void*)0, serPutc);
sleep(10);
tfp_printf("DHT11 run\n\r");
while(1) {
ret = tinudht_read(&tinudht, TINUDHT_PIN);
if (ret == TINUDHT_OK) {
tfp_printf("T=%d H=%d BAT=%d BAT=%d%%\n\r",
tinudht.temperature,
tinudht.humidity,
getVcc(),
getVccRating(50, 45));
} else {
tfp_printf("ret = %d dbg = %d\n\r", ret, tinudht.dbg);
}
sleep(4000);
}
return 0;
}