Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* ****************************************************************************
- * *
- * Name : DHT11 Temperature and humidity digital sensor *
- * MAIN PROGRAM (DEMO) *
- * Author : saper_2 / nolin11 *
- * Contact : nolinno11@gmail.com *
- * Date : 2012.08.28 *
- * Version : 0.1 *
- * License : You are free to use this library in any kind project, but at *
- * least send me a info that YOU are using it. I'll be happy *
- * for memory :) *
- * About : *
- * What to write? Name gives what is this :) *
- * *
- **************************************************************************** */
- #include <avr/io.h>
- #include <inttypes.h>
- #include <avr/pgmspace.h>
- #include <util/delay.h>
- #include <avr/interrupt.h>
- // ------------------------
- #define DEBUG_MODE 1
- // ------------------------
- #include "delay.h"
- #include "lcd.h"
- #include "dht11.h"
- //#include "usart.h"
- /*
- -----------------------------------------------------------------------------------------------------------------
- -----------------------------------------------------------------------------------------------------------------
- -----------------------------------------------------------------------------------------------------------------
- -----------------------------------------------------------------------------------------------------------------
- */
- /* ******************************************************************************************* *
- * Main program start here... *
- * ******************************************************************************************* */
- int main(void) {
- //uint16_t x,y;
- uint8_t r=0;//, dta[5];
- dht11_init();
- lcd_init();
- lcd_cls();
- lcd_str_P((prog_char*)PSTR("DHT11 TEST"));
- lcd_setPos(1,0);
- for (r=0;r<16;r++) {
- lcd_data('+');
- delay1ms(200);
- }
- //usartInit();
- //usartSendStrP((prog_char*)PSTR("\r\nDHT11 test...\r\n"));
- struct DHT11_DATA dht;
- while(1) {
- r = dht11_read((uint8_t*)&dht);
- if (r == 0) {
- lcd_setPos(0,0);
- lcd_str_P((prog_char*)PSTR("DHT11.RH= "));
- lcd_setPos(1,0);
- lcd_str_P((prog_char*)PSTR("DHT11.TMP= "));
- // RH
- lcd_setPos(0,9);
- if (dht.rh<10) lcd_data('0');
- lcd_dec(dht.rh);
- lcd_data('%');
- // There is no need to display decimals because they are always 0...
- lcd_setPos(1,10);
- if (dht.temp<10) lcd_data('0');
- lcd_dec(dht.temp);
- lcd_data(0xdf);
- lcd_data('C');
- // There is no need to display decimals because they are always 0...
- } else {
- lcd_cls();
- lcd_str_P((prog_char*)PSTR("READ ERROR: "));
- lcd_dec(r);
- lcd_setPos(1,0);
- switch (r) {
- case 0: lcd_str_P((prog_char*)PSTR("OK")); break;
- case 1: lcd_str_P((prog_char*)PSTR("CSM-MISMATCH")); break;
- case 2: lcd_str_P((prog_char*)PSTR("ERR-START")); break;
- case 3: lcd_str_P((prog_char*)PSTR("ERR-START-ACK-LO")); break;
- case 4: lcd_str_P((prog_char*)PSTR("ERR-START-ACK-HI")); break;
- case 5: lcd_str_P((prog_char*)PSTR("ERR-BIT-TIME-LOW")); break;
- case 6: lcd_str_P((prog_char*)PSTR("ERR-BIT-TIME-HI")); break;
- }
- delay1ms(5000);
- } // */
- /*
- r = dht11_read();
- dht = (struct DHT11_DATA)dta;
- usartSendStrP((prog_char*)PSTR("DHT11 get_data_res="));
- switch (r) {
- case 0: break;//usartSendStrP((prog_char*)PSTR("OK")); break;
- case 1: break;//usartSendStrP((prog_char*)PSTR("CSM-MISMATCH")); break;
- case 2: break;//usartSendStrP((prog_char*)PSTR("ERROR-START")); break;
- case 3: break;//usartSendStrP((prog_char*)PSTR("ERROR-START-ACK-LOW")); break;
- case 4: break;//usartSendStrP((prog_char*)PSTR("ERROR-START-ACK-HIGH")); break;
- case 5: break;//usartSendStrP((prog_char*)PSTR("ERROR-BIT-TIME-LOW")); break;
- case 6: break;//usartSendStrP((prog_char*)PSTR("ERROR-BIT-TIME-HIGH")); break;
- }
- if (r>5) {
- //usartSendDec(r);
- }
- usartSendStrP((prog_char*)PSTR(" RH="));
- usartSendDec(dht.rh);
- usartSendChar('.');
- usartSendDec(dht.rhd);
- usartSendStrP((prog_char*)PSTR("% TEMP="));
- usartSendDec(dht.temp);
- usartSendChar('.');
- usartSendDec(dht.tempd);
- usartSendStrP((prog_char*)PSTR("oC CSM[r|c]="));
- usartSendDec(dht.csm);
- usartSendChar('|');
- r= dht.rh + dht.rhd + dht.temp + dht.tempd;
- usartSendDec(r);
- usartSendStrP((prog_char*)PSTR("\r\n"));
- // */
- delay1ms(1000);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement