hi,
I have humidity/temperature sensor and LCD connected to ATmega32(below is schematic and code). The code does not work, the values does not get displayed on LCD. Can anybody point out what is wrong in the code? thanks
Codes:
main.c
hdt11.c
I have humidity/temperature sensor and LCD connected to ATmega32(below is schematic and code). The code does not work, the values does not get displayed on LCD. Can anybody point out what is wrong in the code? thanks
Codes:
main.c
C:
#ifndef F_CPU
#deifne F_CPU 8000000UL
#endif
#include <avr/io.h>
#include <util/delay.h>
#include <stdlib.h>
#include <stdio.h>
#include "lcd.h"
#include "hdt11.h"
uint8_t I_RH,D_RH,I_Temp,D_Temp,CheckSum;
int main()
{
// Write your code here
lcdinit();
char data[5];
char humi[]={"Humidity: "};
char temp[] = {"Temp: "};
lcdgoto(1,1);
lcdstr(humi);
lcdgoto(1,2);
lcdstr(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 */
_delay_ms(10);
if ((I_RH + D_RH + I_Temp + D_Temp) != CheckSum)
{
lcdgoto(1,1);
lcdstr("Error");
}
else
{
itoa(I_RH,data,10);
lcdgoto(10,1);
lcdstr(data);
lcdstr(".");
itoa(D_RH,data,10);
lcdstr(data);
lcdstr("%");
itoa(I_Temp,data,10);
lcdgoto(10,2);
lcdstr(data);
lcdstr(".");
itoa(D_Temp,data,10);
lcdstr(data);
lcdchar(0xDF);
lcdstr("C ");
itoa(CheckSum,data,10);
lcdstr(data);
lcdstr(" ");
}
_delay_ms(10);
}
return 0;
}
hdt11.c
C:
#include "hdt11.h"
uint8_t c=0;
void request() /* Microcontroller send start pulse/request */
{
DDRC |= (1<<PC3);
PORTC &= ~(1<<PC3); /* set to low pin */
_delay_ms(18); /* wait for 20ms */
PORTC |= (1<<PC3); /* set to high pin */
}
void response() /* receive response from DHT11 */
{
DDRC &= ~(1<<PC3);
while(PINC & (1<<PC3));
while((PINC & (1<<PC3))==0);
while(PINC & (1<<PC3));
}
uint8_t receive_data() /* receive data */
{
for (int q=0; q<8; q++)
{
while((PINC & (1<<PC3)) == 0); /* check received bit 0 or 1 */
_delay_us(30);
if(PINC & (1<<PC3))/* if high pulse is greater than 30ms */
c = (c<<1)|(0x01); /* then its logic HIGH */
else /* otherwise its logic LOW */
c = (c<<1);
while(PINC & (1<<PC3));
}
return c;
}