#include <reg52.h>
#include "dht11.h"
#include "1602.h"
#include "delay.h"
sbit SET=P1^0;
sbit INC=P1^1;
sbit DEC=P1^2;
sbit Buzzer = P2^0;
sbit KM_T = P3^7;
sbit KM_W = P3^5;
void keyset();
unsigned char TD=0;
unsigned int TH=30;
unsigned int TL=20;
unsigned int WL=25;
unsigned int WH=70;
extern unsigned char temp_value,humi_value;
extern void disptem();
extern void dispwet();
/*******????????**********/
void timerinit()
{
TMOD=0x01;
TH0=-(10000/256);
TL0=-(10000%256);
EA=1;
ET0=1;
}
/*****???0????,????10ms****/
timer0() interrupt 1
{
TD++;
if(TD>=100)
{ TH0=-(10000/256);
TL0=-(10000%256);
TR0=0;
TD=0;
}
keyset();
TH0=-(10000/256);
TL0=-(10000%256);
}
/*****???????******/
void bell()
{
if((temp_value>TH)||(temp_value<TL))
{
Buzzer = 0;
Delayms(10);
}
else Buzzer = 1;
if((humi_value>WH)||(humi_value<WL))
{
Buzzer = 0;
Delayms(10);
}
else Buzzer = 1;
}
void FM_W()
{
if(humi_value < WL)
KM_W = 0;
if(humi_value > WH)
KM_W = 1;
}
void FM_T()
{
if(temp_value <TL)
KM_T = 0;
if(temp_value >TH)
KM_T = 1;
}
/*********???***********/
void main()
{
Buzzer = 1;
KM_T = 1;
KM_W = 1;
LCD_Init(); //?????
Delayms(10); //???????
Lcd_Userchar(); //???????
LCD_Wstring(0,0,"Tem:");
LCD_Wchar(6,0,0x01); //????????
LCD_Wchar(7,0,'C');
LCD_Wstring(9,0,"H30");
LCD_Wstring(13,0,"L20");
LCD_Wstring(0,1,"Wet:");
LCD_Wstring(6,1,"%R");
LCD_Wstring(9,1,"H70");
LCD_Wstring(13,1,"L25");
timerinit();
while(1)
{
Read_DHT11();
disptem();
dispwet();
Delayms(500);
TR0=1;
bell();
FM_W();
FM_T();
}
}
/*************??????***************/
void keyset()
{
unsigned char setcount;
if(SET==0)
{
Delayms(10);
while(SET==0);
setcount++;
}
switch(setcount)
{
case 1:
{
char displaynum_1[8];
INC=1;
DEC=1;
if((INC==0)&(TH<50))
{
TH++;
while(INC==0);
}
else if((DEC==0)&(TH>TL))
{
TH--;
while(DEC==0);
}
sprintf(displaynum_1,"%2i",TH);
LCD_Wstring(10,0,displaynum_1);
LCD_Wcom(0x80+11);
LCD_Wcom(0x0f);
}break;
case 2:
{
char displaynum_2[8];
INC=1;
DEC=1;
if((INC==0)&(TL<TH))
{
if(INC==0)
{
TL++;
while(INC==0);
}
}
else if((DEC==0)&(TL>0))
{
if(DEC==0)
TL--;
while(DEC==0);
}
sprintf(displaynum_2,"%2i",TL);
LCD_Wstring(14,0,displaynum_2);
LCD_Wcom(0x80+15);
LCD_Wcom(0x0f);
}
break;
case 3:
{
char displaynum_3[8];
INC=1;
DEC=1;
if((INC==0)&(WH<95))
{
WH++;
while(INC==0);
}
else if((DEC==0)&(WH>WL))
{
WH--;
while(DEC==0);
}
sprintf(displaynum_3,"%2i",WH);
LCD_Wstring(10,1,displaynum_3);
LCD_Wcom(0x80+0x40+11);
LCD_Wcom(0x0f);
}
break;
case 4:
{
char displaynum_4[8];
INC=1;
DEC=1;
if((INC==0)&(WL<WH))
{
WL++;
while(INC==0);
}
else if((DEC==0)&(WL>0))
{
WL--;
while(DEC==0);
}
sprintf(displaynum_4,"%2i",WL);
LCD_Wstring(14,1,displaynum_4);
LCD_Wcom(0x80+0x40+15);
LCD_Wcom(0x0f);
}
break;
case 5:
{
setcount=0;
LCD_Wcom(0x0c);
}
break;
default :break;
}
}
|