porklib: Simple library for programming Arduino in C
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
avr-lib/examples/onewire_DS1820/main.c

42 lines
653 B

9 years ago
#include <avr/pgmspace.h>
#include <util/delay.h>
#include <stdint.h>
#include "lib/uart.h"
#include "lib/stream.h"
#include "lib/onewire.h"
#define T 2
void main()
{
uart_init(9600);
uart_puts_P(PSTR("*** OneWire test ***\r\n"));
while(1)
{
_delay_ms(100);
ow_reset(T);
ow_send(T, SKIP_ROM);
ow_send(T, CONVERT_T);
if(!ow_wait_ready(T)) {
uart_puts_P(PSTR("Wait timeout!\r\n"));
continue;
}
ow_reset(T);
ow_send(T, SKIP_ROM);
int16_t temp = ds1820_read_temp_c(T);
if (temp == TEMP_ERROR) {
uart_puts_P(PSTR("Read error!\r\n"));
} else {
put_i16f(uart, temp, 1);
uart_puts_P(PSTR(" °C\r\n"));
}
}
}