Advertisement
saper_2

dht11 - main program demo

Nov 27th, 2012
280
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 4.95 KB | None | 0 0
  1. /* ****************************************************************************
  2.    *                                                                          *
  3.    * Name    : DHT11 Temperature and humidity digital sensor                  *
  4.    *           MAIN PROGRAM (DEMO)                                            *
  5.    * Author  : saper_2 / nolin11                                              *
  6.    * Contact : nolinno11@gmail.com                                            *
  7.    * Date    : 2012.08.28                                                     *
  8.    * Version : 0.1                                                            *
  9.    * License : You are free to use this library in any kind project, but at   *
  10.    *           least send me a info that YOU are using it. I'll be happy      *
  11.    *           for memory :)                                                  *
  12.    * About   :                                                                *
  13.    *           What to write? Name gives what is this :)                      *
  14.    *                                                                          *
  15.    **************************************************************************** */
  16.  
  17. #include <avr/io.h>
  18. #include <inttypes.h>
  19. #include <avr/pgmspace.h>
  20. #include <util/delay.h>
  21. #include <avr/interrupt.h>
  22. // ------------------------
  23. #define DEBUG_MODE 1
  24. // ------------------------
  25. #include "delay.h"
  26. #include "lcd.h"
  27. #include "dht11.h"
  28. //#include "usart.h"
  29. /*
  30.  -----------------------------------------------------------------------------------------------------------------
  31.  -----------------------------------------------------------------------------------------------------------------
  32.  -----------------------------------------------------------------------------------------------------------------
  33.  -----------------------------------------------------------------------------------------------------------------
  34. */
  35.  
  36.  
  37. /* ******************************************************************************************* *
  38.  *                             Main program start here...                                      *
  39.  * ******************************************************************************************* */
  40.  
  41. int main(void) {
  42.     //uint16_t x,y;
  43.     uint8_t r=0;//, dta[5];
  44.  
  45.     dht11_init();
  46.     lcd_init();
  47.     lcd_cls();
  48.     lcd_str_P((prog_char*)PSTR("DHT11 TEST")); 
  49.     lcd_setPos(1,0);
  50.     for (r=0;r<16;r++) {
  51.         lcd_data('+');
  52.         delay1ms(200);
  53.     }
  54.     //usartInit();
  55.     //usartSendStrP((prog_char*)PSTR("\r\nDHT11 test...\r\n"));
  56.    
  57.     struct DHT11_DATA dht;
  58.     while(1) {
  59.         r = dht11_read((uint8_t*)&dht);
  60.         if (r == 0) {
  61.             lcd_setPos(0,0);
  62.             lcd_str_P((prog_char*)PSTR("DHT11.RH=       "));
  63.             lcd_setPos(1,0);
  64.             lcd_str_P((prog_char*)PSTR("DHT11.TMP=      "));
  65.        
  66.             // RH
  67.             lcd_setPos(0,9);
  68.             if (dht.rh<10) lcd_data('0');
  69.             lcd_dec(dht.rh);
  70.             lcd_data('%');
  71.             // There is no need to display decimals because they are always 0...
  72.            
  73.             lcd_setPos(1,10);
  74.             if (dht.temp<10) lcd_data('0');
  75.             lcd_dec(dht.temp);
  76.             lcd_data(0xdf);
  77.             lcd_data('C');
  78.             // There is no need to display decimals because they are always 0...
  79.            
  80.         } else {
  81.             lcd_cls();
  82.             lcd_str_P((prog_char*)PSTR("READ ERROR: "));
  83.             lcd_dec(r);
  84.             lcd_setPos(1,0);
  85.             switch (r) {
  86.                 case 0: lcd_str_P((prog_char*)PSTR("OK")); break;
  87.                 case 1: lcd_str_P((prog_char*)PSTR("CSM-MISMATCH")); break;
  88.                 case 2: lcd_str_P((prog_char*)PSTR("ERR-START")); break;
  89.                 case 3: lcd_str_P((prog_char*)PSTR("ERR-START-ACK-LO")); break;
  90.                 case 4: lcd_str_P((prog_char*)PSTR("ERR-START-ACK-HI")); break;
  91.                 case 5: lcd_str_P((prog_char*)PSTR("ERR-BIT-TIME-LOW")); break;
  92.                 case 6: lcd_str_P((prog_char*)PSTR("ERR-BIT-TIME-HI")); break;
  93.             }
  94.             delay1ms(5000);
  95.         } // */
  96.        
  97.         /*
  98.         r = dht11_read();
  99.         dht = (struct DHT11_DATA)dta;
  100.         usartSendStrP((prog_char*)PSTR("DHT11 get_data_res="));
  101.         switch (r) {
  102.             case 0: break;//usartSendStrP((prog_char*)PSTR("OK")); break;
  103.             case 1: break;//usartSendStrP((prog_char*)PSTR("CSM-MISMATCH")); break;
  104.             case 2: break;//usartSendStrP((prog_char*)PSTR("ERROR-START")); break;
  105.             case 3: break;//usartSendStrP((prog_char*)PSTR("ERROR-START-ACK-LOW")); break;
  106.             case 4: break;//usartSendStrP((prog_char*)PSTR("ERROR-START-ACK-HIGH")); break;
  107.             case 5: break;//usartSendStrP((prog_char*)PSTR("ERROR-BIT-TIME-LOW")); break;
  108.             case 6: break;//usartSendStrP((prog_char*)PSTR("ERROR-BIT-TIME-HIGH")); break;
  109.         }
  110.         if (r>5) {
  111.             //usartSendDec(r);
  112.         }
  113.         usartSendStrP((prog_char*)PSTR(" RH="));
  114.         usartSendDec(dht.rh);
  115.         usartSendChar('.');
  116.         usartSendDec(dht.rhd);
  117.         usartSendStrP((prog_char*)PSTR("% TEMP="));
  118.         usartSendDec(dht.temp);
  119.         usartSendChar('.');
  120.         usartSendDec(dht.tempd);
  121.         usartSendStrP((prog_char*)PSTR("oC CSM[r|c]="));
  122.         usartSendDec(dht.csm);
  123.         usartSendChar('|');
  124.         r= dht.rh + dht.rhd + dht.temp + dht.tempd;
  125.         usartSendDec(r);
  126.         usartSendStrP((prog_char*)PSTR("\r\n"));
  127.         // */
  128.         delay1ms(1000);
  129.     }
  130. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement