Untitled

 avatar
unknown
plain_text
3 years ago
1.5 kB
79
Indexable
#define F_CPU 8000000UL			/* Define CPU Frequency e.g. here 8MHz */
#include <avr/io.h>			/* Include AVR std. library file */
#include <util/delay.h>			/* Include Delay header file */
#include "LCD16X2.h"
#include "DHT11.h"
#include "stdlib.h"


int main()
{
	char data[20];
	LCD_Init();			/* Initialization of LCD*/
	LCD_Clear();
	LCD_String_xy(0,0);
	LCD_String("U =");
	LCD_String_xy(1,0);
	LCD_String("T = ");
	
	while(1){
		
		Request();		/* send start pulse */
		Response();		/* receive response */
		I_RH=Receive_data();	/* store first eight bit in I_RH */
		D_RH=Receive_data();	/* store next eight bit in D_RH */ 
		I_Temp=Receive_data();	/* store next eight bit in I_Temp */
		D_Temp=Receive_data();	/* store next eight bit in D_Temp */ 
		CheckSum=Receive_data();/* store next eight bit in CheckSum */
		
		if ((I_RH + D_RH + I_Temp + D_Temp) != CheckSum)
		{
			LCD_String_xy(0,0);
			LCD_String("Error");
		}
		else
		{
			itoa(I_RH,data,10); // convert int to string
			LCD_String_xy(0,6);
			LCD_String(data);
			LCD_String(".");
			
			itoa(D_RH,data,10);
			LCD_String(data);
			LCD_String("%");

			itoa(I_Temp,data,10);
			LCD_String_xy(1,6);
			LCD_String(data);
			LCD_String(".");
			
			itoa(D_Temp,data,10);
			LCD_String(data);
			LCD_Char(0xDF);
			LCD_String("C ");
			
			itoa(CheckSum,data,10);
			LCD_String(data);
			LCD_String(" ");
	
		}
		
		_delay_ms(10);
	}
}