Statistics
| Branch: | Tag: | Revision:

root / analog_exp / analog_exp.c @ 168:bfc84ee2839b

History | View | Annotate | Download (1.2 kB)

1
#include <avr/io.h>
2
#include <avr/interrupt.h>
3
#include <util/delay.h>
4
5
#include "board.h"
6
#include "debug.h"
7
#include "onewire.h"
8
#include "excitation.h"
9
#include "analog_exp.h"
10
11
onewire_id onewire_devices[4];
12
13
static inline void setup(void) {
14
    debug_setup();
15
    exc_setup();
16
17
    exc_enable(0, 0xFF);
18
}
19
20
static inline void loop(void) {
21
    ds18b20_scratchpad_t scratchpad;
22
23
    _delay_ms(1000);
24
    uint8_t n_devices = 4;
25
    onewire_searchrom(onewire_devices, &n_devices);
26
27
    onewire_skiprom();
28
    onewire_convert_t();
29
    _delay_ms(750);
30
31
    debugf("%d devices\n", n_devices);
32
    for(uint8_t i=0; i<n_devices; i++) {
33
        debugf("  0x");
34
        for(uint8_t j=0; j<sizeof(onewire_id); j++) {
35
            debugf("%02X", onewire_devices[i][j]);
36
        }
37
        uint8_t crc = onewire_crc_rom(onewire_devices[i]);
38
        debugf(" crc: %d\n", crc);
39
40
        onewire_matchrom(onewire_devices[i]);
41
        crc = onewire_read_scratchpad(&scratchpad);
42
        debugf("    scratchpad crc: %d\n", crc);
43
        debugf("    temperature: %d.%04d\n", scratchpad.temperature >> 4, 
44
            (scratchpad.temperature & 0xF) * 625 );
45
    }
46
}
47
48
int main(void) {
49
    setup();
50
    sei();
51
    for(;;) loop();
52
    return 1;
53
}
54