Advertisement
Guest User

Untitled

a guest
Oct 6th, 2015
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.60 KB | None | 0 0
  1. /*
  2. * main.c
  3. *
  4. * Created on: 30-10-2014
  5. * Author: matt
  6. */
  7. #include <avr/io.h>
  8. #include <util/delay.h>
  9.  
  10. #include "1wire/ds18x20.h"
  11.  
  12.  
  13. uint16_t DS18X20_temp_to_decicel(uint8_t subzero, uint8_t cel, uint8_t cel_frac_bits)
  14. {
  15. uint16_t h;
  16. uint8_t i;
  17. uint8_t need_rounding[] = { 1, 3, 4, 6, 9, 11, 12, 14 };
  18.  
  19. h = cel_frac_bits*DS18X20_FRACCONV/1000;
  20. h += cel*10;
  21. if (!subzero) {
  22. for (i=0; i<sizeof(need_rounding); i++) {
  23. if ( cel_frac_bits == need_rounding[i] ) {
  24. h++;
  25. break;
  26. }
  27. }
  28. }
  29. return h;
  30. }
  31.  
  32.  
  33. int main( void ) {
  34.  
  35. DDRB |= (1<<PB4); //kierunek lini diody led jako wyjscie
  36. PORTB |= (1<<PB4); //zalaczenie diody led - stan wysoki
  37.  
  38. //DS18X20_start_meas( DS18X20_POWER_EXTERN, NULL ); //rozkaz wykonania pomiarow temperatury do wszystkich czujnikow na magistrali 1wire
  39. //_delay_ms(750); //dokonanie konwersji
  40. uint16_t decicelsius;
  41. uint8_t subzero, cel, cel_frac_bits;
  42. double temp;
  43.  
  44. while(1) {
  45. DS18X20_start_meas( DS18X20_POWER_PARASITE, NULL) ;
  46. _delay_ms( DS18B20_TCONV_12BIT );
  47.  
  48. DS18X20_read_meas_single( DS18B20_ID, &subzero, &cel, &cel_frac_bits );
  49. decicelsius = DS18X20_temp_to_decicel(subzero, cel, cel_frac_bits);
  50. temp = decicelsius/10.0;
  51. if (temp >= 30) {
  52. DDRB |= (1<<PB4);
  53. }
  54. else if (temp < 29 && temp > 26) {
  55. DDRB ^= (1<<PB4); //ustaw pin PB4 na przeciwstawny do wyj?cia
  56. }
  57. else if (temp < 25) {
  58. DDRB &= ~(1<<PB4);
  59. }
  60.  
  61.  
  62.  
  63.  
  64. }
  65.  
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement