ko hiểu sao em sai chỗ nào mà khi nd quá 40 độ lại ko có đèn báo
#include "main.h"
#include "lcd_new.h"
#use FAST_IO(B)
#use FAST_IO(C)
#use FAST_IO(D)
#use FAST_IO(E)
#byte PORTA=0x05
#byte PORTB=0x06
#byte PORTC=0x07
#byte PORTD=0x08
#byte PORTE=0x09
#bit led = portD.0
#bit DHT_DATA = PORTA.1
#define SET_PIN SET_TRIS_A
#define DHT_ER 0
#define DHT_OK 1
#define DHT_ND 0
#define DHT_DA 1
float nhietdo = 0, doam=0;
unsigned char DHT_GetTemHumi (unsigned char select)
{
unsigned char buffer[5]={0,0,0,0,0};
unsigned char ii,i,checksum;
SET_PIN(0x00);// set la cong ra
DHT_DATA=1;
delay_us(60);
DHT_DATA = 0;
delay_ms(25); // it nhat 18ms
DHT_DATA = 1;
SET_PIN(0xff);
delay_us(40);
if(DHT_DATA==1)return DHT_ER ;
else while(DHT_DATA==0); //Doi DaTa len 1
delay_us(60); //60
if(DHT_DATA==0)return DHT_ER;
else while((DHT_DATA==1)); //Doi Data ve 0
//Bat dau doc du lieu
for(i=0;i<5;i++)
{
for(ii=0;ii<8;ii++)
{
while(DHT_DATA==0);//Doi Data len 1 !DHT_DATA
delay_us(50); //50
if(DHT_DATA==1)
{
buffer[i]|=(1<<(7-ii));
while(DHT_DATA==1);//Doi Data xuong 0
}
}
}
//Tinh toan check sum
checksum=buffer[0]+buffer[1]+buffer[2]+buffer[3];
//Kiem tra check sum
if((checksum)!=buffer[4])return DHT_ER;
//Lay du lieu
if (select==DHT_ND)
{
//Return the value has been choosen
return(buffer[2]);
}
else if(select==DHT_DA)
{
return(buffer[0]);
}
return DHT_OK;
}
//------------------------------------------------------//
void main()
{
set_tris_d(0xff);
set_tris_a(0xff);
lcd_init();
delay_ms(200);
lcd_gotoxy(7,1);
lcd_putc('H');
delay_ms(100);
lcd_putc('I');
delay_ms(200);
lcd_putc('!');
delay_ms(1000);
printf(lcd_putc,"\f " );
printf(lcd_putc,"dangphuctiep");
delay_ms(1000);
lcd_gotoxy(1,2);
printf(lcd_putc,"demo" );
delay_ms(2000);
printf(lcd_putc,"\f " );
while(TRUE)
{
set_tris_d(0xff);
nhietdo= DHT_GetTemHumi (DHT_ND);
delay_ms(400);
lcd_gotoxy(1,1);
printf(lcd_putc,"Nhiet do: " );
lcd_gotoxy(10,1);
printf(lcd_putc,"%3.1f ^C",nhietdo);
delay_ms(800);
if (nhietdo>=40)
{
led=0;
}
doam= DHT_GetTemHumi (DHT_DA);
lcd_gotoxy(1,2);
printf(lcd_putc,"Do am: " );
lcd_gotoxy(10,2);
printf(lcd_putc,"%3.1f ",doam);
lcd_gotoxy(14,2);
lcd_putc('%');
delay_ms(1000);
}
}
#include "main.h"
#include "lcd_new.h"
#use FAST_IO(B)
#use FAST_IO(C)
#use FAST_IO(D)
#use FAST_IO(E)
#byte PORTA=0x05
#byte PORTB=0x06
#byte PORTC=0x07
#byte PORTD=0x08
#byte PORTE=0x09
#bit led = portD.0
#bit DHT_DATA = PORTA.1
#define SET_PIN SET_TRIS_A
#define DHT_ER 0
#define DHT_OK 1
#define DHT_ND 0
#define DHT_DA 1
float nhietdo = 0, doam=0;
unsigned char DHT_GetTemHumi (unsigned char select)
{
unsigned char buffer[5]={0,0,0,0,0};
unsigned char ii,i,checksum;
SET_PIN(0x00);// set la cong ra
DHT_DATA=1;
delay_us(60);
DHT_DATA = 0;
delay_ms(25); // it nhat 18ms
DHT_DATA = 1;
SET_PIN(0xff);
delay_us(40);
if(DHT_DATA==1)return DHT_ER ;
else while(DHT_DATA==0); //Doi DaTa len 1
delay_us(60); //60
if(DHT_DATA==0)return DHT_ER;
else while((DHT_DATA==1)); //Doi Data ve 0
//Bat dau doc du lieu
for(i=0;i<5;i++)
{
for(ii=0;ii<8;ii++)
{
while(DHT_DATA==0);//Doi Data len 1 !DHT_DATA
delay_us(50); //50
if(DHT_DATA==1)
{
buffer[i]|=(1<<(7-ii));
while(DHT_DATA==1);//Doi Data xuong 0
}
}
}
//Tinh toan check sum
checksum=buffer[0]+buffer[1]+buffer[2]+buffer[3];
//Kiem tra check sum
if((checksum)!=buffer[4])return DHT_ER;
//Lay du lieu
if (select==DHT_ND)
{
//Return the value has been choosen
return(buffer[2]);
}
else if(select==DHT_DA)
{
return(buffer[0]);
}
return DHT_OK;
}
//------------------------------------------------------//
void main()
{
set_tris_d(0xff);
set_tris_a(0xff);
lcd_init();
delay_ms(200);
lcd_gotoxy(7,1);
lcd_putc('H');
delay_ms(100);
lcd_putc('I');
delay_ms(200);
lcd_putc('!');
delay_ms(1000);
printf(lcd_putc,"\f " );
printf(lcd_putc,"dangphuctiep");
delay_ms(1000);
lcd_gotoxy(1,2);
printf(lcd_putc,"demo" );
delay_ms(2000);
printf(lcd_putc,"\f " );
while(TRUE)
{
set_tris_d(0xff);
nhietdo= DHT_GetTemHumi (DHT_ND);
delay_ms(400);
lcd_gotoxy(1,1);
printf(lcd_putc,"Nhiet do: " );
lcd_gotoxy(10,1);
printf(lcd_putc,"%3.1f ^C",nhietdo);
delay_ms(800);
if (nhietdo>=40)
{
led=0;
}
doam= DHT_GetTemHumi (DHT_DA);
lcd_gotoxy(1,2);
printf(lcd_putc,"Do am: " );
lcd_gotoxy(10,2);
printf(lcd_putc,"%3.1f ",doam);
lcd_gotoxy(14,2);
lcd_putc('%');
delay_ms(1000);
}
}
Comment