|
#include "reg51.h"
#include "stdio.h"
#include "intrins.h"
#include "LCD1602.h"
#include "fmq.h"
#include "key.h"
#define uchar unsigned char
#define uint unsigned int
sbit dq=P2^3;
uchar wenduh;
uchar wendul;
uchar shiduh;
uchar shidul;
uchar wendu;
uchar shidu;
uchar wendus;
uchar shidus;
uchar wendux;
uchar shidux;
uchar keyv;
uchar mode;
uchar n=0;
uchar x;
//uchar flag=2;
void delay1(uint n)
{
uint i,j;
for(i=0;i<n;i++)
for(j=0;j<100;j++);
}
bit init_dht11()
{
uchar num;
bit flag;
dq=0;
delay1(20);
dq=1;
for(num=0;num<11;num++);
for(num=0;num<12;num++);
flag=dq;
for(num=0;num<11;num++);
for(num=0;num<24;num++);
return flag;
}
uchar dht11_rd_char()
{
uchar byte=0;
uchar num;
uchar num1;
while(dq==1);
for(num1=0;num1<8;num1++)
{
while(dq==0);
byte<<=1;
for(num=0;dq==1;num++);
if(num<10)
byte|=0x00;
else
byte|=0x01;
}
return byte;
}
void dht11_dushu()
{
uchar num;
if(init_dht11()==0)
{
shiduh=dht11_rd_char();
shidul=dht11_rd_char();
wenduh=dht11_rd_char();
wendul=dht11_rd_char();
shidu=(shiduh*256+shidul)/10;
wendu=(wenduh*256+wendul)/10;
for(num=0;num<20;num++);
dq=1;
}
else
{
shidu=00;
wendu=00;
}
}
void display()
{
write_char(1,0,'w');
write_char(1,1,'n');
write_char(1,2,'d');
write_char(1,3,'u');
write_char(1,4,':');
write_data(wendu/10%10+48);
write_data(wendu%10+48);
write_char(1,9,0xdf);
write_char(1,10,'C');
write_char(2,0,'s');
write_char(2,1,'h');
write_char(2,2,'i');
write_char(2,3,'d');
write_char(2,4,'u');
write_char(2,5,':');
write_data(shidu/10%10+48);
write_data(shidu%10+48);
write_char(2,10,'%');
}
void main()
{
wendu=0;
shidu=0;
wendus=40;
wendux=20;
shidus=90;
shidux=20;
delay1(100);
Init_LCD1602();
while(1)
{
dht11_dushu();
delay1(300);
if(n%2==0)
{
display();
delay1(300);
}
else if(n%2==1)
{
write_str(1,0,"wMax:");
write_data(wendus/10%10+48);
write_data(wendus%10+48);
write_str(2,0,"wMin:");
write_data(wendux/10%10+48);
write_data(wendux%10+48);
write_str(1,8,"sMax:");
write_data(shidus/10%10+48);
write_data(shidus%10+48);
write_str(2,8,"sMin:");
write_data(shidux/10%10+48);
write_data(shidux%10+48);
if(k2==0)
{
write_com(0x01);
delay1(10);
if(k2==0)
{
x++;
}
}
if(x%4==1)
{
write_char(1,7,'<');
if(k3==0)
{
delay1(10);
if(k3==0)
{
wendus++;
}
}
else if(k4==0)
{
delay1(10);
if(k4==0)
{
wendus--;
}
}
}
else if(x%4==2)
{
write_char(2,7,'<');
if(k3==0)
{
delay1(10);
if(k3==0)
{
wendux++;
}
}
else if(k4==0)
{
delay1(10);
if(k4==0)
{
wendux--;
}
}
}
else if(x%4==3)
{
write_char(1,15,'<');
if(k3==0)
{
delay1(10);
if(k3==0)
{
shidus++;
}
}
else if(k4==0)
{
delay1(10);
if(k4==0)
{
shidus--;
}
}
}
else if(x%4==0)
{
write_char(2,15,'<');
if(k3==0)
{
delay1(10);
if(k3==0)
{
shidux++;
}
}
else if(k4==0)
{
delay1(10);
if(k4==0)
{
shidux--;
}
}
}
}
if(k1==0)
{
delay1(10);
if(k1==0)
{
n++;
write_com(0x01);
}
}
}
}
|
|