Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * main.c
- *
- * Created on: 30-10-2014
- * Author: matt
- */
- #include <avr/io.h>
- #include <util/delay.h>
- #include "1wire/ds18x20.h"
- uint16_t DS18X20_temp_to_decicel(uint8_t subzero, uint8_t cel, uint8_t cel_frac_bits)
- {
- uint16_t h;
- uint8_t i;
- uint8_t need_rounding[] = { 1, 3, 4, 6, 9, 11, 12, 14 };
- h = cel_frac_bits*DS18X20_FRACCONV/1000;
- h += cel*10;
- if (!subzero) {
- for (i=0; i<sizeof(need_rounding); i++) {
- if ( cel_frac_bits == need_rounding[i] ) {
- h++;
- break;
- }
- }
- }
- return h;
- }
- int main( void ) {
- DDRB |= (1<<PB4); //kierunek lini diody led jako wyjscie
- PORTB |= (1<<PB4); //zalaczenie diody led - stan wysoki
- //DS18X20_start_meas( DS18X20_POWER_EXTERN, NULL ); //rozkaz wykonania pomiarow temperatury do wszystkich czujnikow na magistrali 1wire
- //_delay_ms(750); //dokonanie konwersji
- uint16_t decicelsius;
- uint8_t subzero, cel, cel_frac_bits;
- double temp;
- while(1) {
- DS18X20_start_meas( DS18X20_POWER_PARASITE, NULL) ;
- _delay_ms( DS18B20_TCONV_12BIT );
- DS18X20_read_meas_single( DS18B20_ID, &subzero, &cel, &cel_frac_bits );
- decicelsius = DS18X20_temp_to_decicel(subzero, cel, cel_frac_bits);
- temp = decicelsius/10.0;
- if (temp >= 30) {
- DDRB |= (1<<PB4);
- }
- else if (temp < 29 && temp > 26) {
- DDRB ^= (1<<PB4); //ustaw pin PB4 na przeciwstawny do wyj?cia
- }
- else if (temp < 25) {
- DDRB &= ~(1<<PB4);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement