Advertisement
saper_2

dht11.h

Nov 27th, 2012
360
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.93 KB | None | 0 0
  1. /* ****************************************************************************
  2.    *                                                                          *
  3.    * Name    : DHT11 Temperature and humidity digital sensor                  *
  4.    *            (cheap version of Sensirion SHT11)                            *
  5.    * Author  : saper_2 / nolin11                                              *
  6.    *                                                                          *
  7.    *  Checkout dht11.c for complete author & license inforamtion about this   *
  8.    *                                                                          *
  9.    **************************************************************************** */
  10.  
  11. #ifndef _DHT11_DRIVER_H_
  12. #define _DHT11_DRIVER_H_
  13.  
  14. struct DHT11_DATA {
  15.     uint8_t rh; // integral part of RH
  16.     uint8_t rhd; // decimal part of RH
  17.     uint8_t temp; // integral part of temperature
  18.     uint8_t tempd; // decimal part of temperature
  19.     uint8_t csm; // checksum
  20. };
  21.  
  22. // data line need a pull-up (4-10k - 5k1 is recomended)
  23. #define DHT_PORT PORTD
  24. #define DHT_PIN PIND
  25. #define DHT_DDR DDRD
  26. #define DHT_PN 3
  27.  
  28. #define DHT_DATA_INT_SOURCE_NOT_USED 0
  29. #define DHT_DATA_INT_SOURCE_INT0 0
  30. #define DHT_DATA_INT_SOURCE_INT1 1
  31.  
  32. #define DHT_DATA_INT_SOURCE DHT_DATA_INT_SOURCE_NOT_USED
  33.  
  34.  
  35. #define dht_data_in DHT_DDR &= ~(1<<DHT_PN);
  36. #define dht_data_out DHT_DDR |= (1<<DHT_PN);
  37. #define dht_data_hi DHT_PORT |= 1<<DHT_PN; dht_data_in;
  38. #define dht_data_lo DHT_PORT &= ~(1<<DHT_PN); dht_data_out;
  39. #define dht_get_data ((DHT_PIN & (1<<DHT_PN)) == (1<<DHT_PN))
  40.  
  41. // init ports, interrupts, etc...
  42. void dht11_init(void);
  43.  
  44. #define DHT11_READ_OK 0
  45. #define DHT11_READ_ERROR_CSM 1
  46. #define DHT11_READ_ERROR_START 2
  47. #define DHT11_READ_ERROR_ACK 3
  48. #define DHT11_READ_ERROR_ACK2 4
  49. #define DHT11_READ_ERROR_TIME 5
  50. #define DHT11_READ_ERROR_TIME2 6
  51.  
  52. uint8_t dht11_read(uint8_t* data);
  53. //uint8_t dht11_read(void);
  54.  
  55.  
  56.  
  57.  
  58. #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement