dh11 humidity sensor with codevision

Status
Not open for further replies.

mshh

Full Member level 6
Joined
May 30, 2010
Messages
349
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,296
Location
usa
Activity points
3,871
I want to read humidity and temperature from sensor DH11.
I used this code from this page https://electronicwings.com/avr-atmega/dht11-sensor-interfacing-with-atmega16-32

there is error in this program
and I want to modify it using codevision

Error: C:\Users\mado\Desktop\egg\clk.c(10): '(' expected
Code:
#include <mega16.h>
 #include <stdlib.h>
#include <stdio.h>

#include <alcd.h>
#include <delay.h>

#define DHT11_PIN 6

uint8_t c=0,I_RH,D_RH,I_Temp,D_Temp,CheckSum;

void Request()				/* Microcontroller send start pulse/request */
{
	DDRD |= (1<<DHT11_PIN);
	PORTD &= ~(1<<DHT11_PIN);	/* set to low pin */
	delay_ms(20);			/* wait for 20ms */
	PORTD |= (1<<DHT11_PIN);	/* set to high pin */
}

void Response()				/* receive response from DHT11 */
{
	DDRD &= ~(1<<DHT11_PIN);
	while(PIND & (1<<DHT11_PIN));
	while((PIND & (1<<DHT11_PIN))==0);
	while(PIND & (1<<DHT11_PIN));
}

uint8_t Receive_data()			/* receive data */
{	
	for (int q=0; q<8; q++)
	{
		while((PIND & (1<<DHT11_PIN)) == 0);  /* check received bit 0 or 1 */
		delay_us(30);
		if(PIND & (1<<DHT11_PIN))/* if high pulse is greater than 30ms */
		c = (c<<1)|(0x01);	/* then its logic HIGH */
		else			/* otherwise its logic LOW */
		c = (c<<1);
		while(PIND & (1<<DHT11_PIN));
    }
    return c;
}

int main(void)
{    
    char data[5];
    lcd_init(16);            /* Initialize LCD */
    lcd_clear();            /* Clear LCD */
    lcd_gotoxy(0,0);        /* Enter column and row position */
     lcd_putsf("Humidity =");
    lcd_gotoxy(0,1);
    lcd_putsf("Temp = ");  
    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_gotoxy(0,0);
			lcd_putsf("Error");
		}
		
		else
		{	
			itoa(I_RH,data,10);
			lcd_gotoxy(11,0);
			lcd_putsf(data);
			lcd_putsf(".");
			
			itoa(D_RH,data,10);
			lcd_putsf(data);
			lcd_putsf("%");

			itoa(I_Temp,data,10);
			lcd_gotoxy(6,1);
			lcd_putsf(data);
			lcd_putsf(".");
			
			itoa(D_Temp,data,10);
			lcd_putsf(data);
			lcddata(0xDF);
			lcd_putsf("C ");
			
			itoa(CheckSum,data,10);
			lcd_print(data);
			lcd_print(" ");
		}
				
	delay_ms(10);
	}	
}

- - - Updated - - -

as in the pic
 
Last edited:

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…