Home > other >  Humidity temperature acquisition system based on MCU
Humidity temperature acquisition system based on MCU

Time:10-20

Based on collecting the data of temperature and humidity stc89c52 single-chip microcomputer system

Code:
#include
# define uint unsigned int
# define uchar unsigned char
#include

Typedef bit BOOL;

Sbit IO P1=^ 1;//(????????? )
Sbit bee P1=^ 0;
Sbit rs=P2 ^ 5;
Sbit rw=P2 ^ 6;
Sbit ep=P2 ^ 7;
Bit flag_300ms;

Sbit K1=p ^ 2;
Sbit K2=P1 ^ 3;
Sbit K3=P1 ^ 4;

Uchar yemian=0;//?????????????
Uchar flat=1;
Uchar data_byte;
Uchar RH, RL, TH, TL;
Uchar WenDu, ShiDu;//?????????????????
# include "eeprom52. H"


/* * * * * * * * * * * * * * * * * * * * * * * * * * * *??????????? * * * * * * * * * * * * * * * * * * * * * * * * * * * */
Void delay (uchar ms)
{//????????
Uchar I;
While (ms -)
{
For (I=0; i<250; I++);
}
}

Void delay1 ()//??????? 10 us
{
uchar i;
i--;
i--;
i--;
i--;
i--;
i--;
}
Void longdelay uchar (s)//???????
{
While (s -)
{
Delay (20);
}
}



/* * * * * * * * * * * * * * * * * *?????????? 浽???????? Eeprom?? * * * * * * * * * * * * * * * * * */
Void write_eeprom ()
{
SectorErase (0 x2000);
Byte_write (0 x2000, WenDu);
Byte_write (0 x2001, ShiDu);
Byte_write (0 x2060, a_a);
}

/* * * * * * * * * * * * * * * * * *???????????????????? Eeprom? ж??????? * * * * * * * * * * * * * * * * */
Void read_eeprom ()
{
WenDu=byte_read (0 x2000);
ShiDu=byte_read x2001 (0);
X2060 a_a=byte_read (0);
}

/* * * * * * * * * * * * * *??????????? Eeprom??????? * * * * * * * * * * * * * * * * */
Void init_eeprom ()
{
Read_eeprom ();//???
If (a_a!//=2)? Mu??????????????????????? Eeprom
{
WenDu=30;
ShiDu=80;
A_a=2;
Write_eeprom ();
}
}



/* * * * * * * * * * * * * * * * * * * *???????????????? * * * * * * * * * * * * * * * * * * */
Void the warn ()//??????????
{

If (TH>=WenDu)//????????????????? Is???????????

{
Bee=0;//??????

}

If (RH>=ShiDu)//????????????????? Is????????

{
Bee=0;//??????
}


If (TH{
Bee=1;//????????
}


}

/* * * * * * * * * * * * * * * * * * * * * * * * LCD??????? * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

BOOL lcd_bz ()//?????? The LCD? Mu????
{
BOOL result;
Rs=0;
Rw=1;
Ep=1;
Result=(BOOL) (P0 & amp; 0 x80);
Ep=0;
Return the result.
}

Void write_cmd uchar (CMD)//д???????
{
While (lcd_bz ());
Rs=0;
Rw=0;
Ep=0;
P0=CMD;
Ep=1;
Ep=0;
}

Void write_addr (uchar addr)//д???????
{
Write_cmd (addr | 0 x80);
}

Void write_byte (uchar dat)//д???????
{
While (lcd_bz ());
Rs=1;
Rw=0;
Ep=0;
P0=dat;
Ep=1;
Ep=0;
}

Void lcd_init ()//?????
{
X38 write_cmd (0);
Delay (1);
Write_cmd (0 x08);
Delay (1);
Write_cmd (0 x01);
Delay (1);
Write_cmd x06 (0);
Delay (1);
X0c write_cmd (0);
Delay (1);
}

Void the display (uchar addr, uchar q)//??????????????????????????
{
Delay (1);
Write_addr (addr);
Write_byte (q);
Delay (1);

}

/* * * * * * * * * * * * * * * * * * * * * * * DHT11??????????? * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

Void the start ()//??????
{
IO=1;
Delay1 ();
IO=0;
Delay (20);//& gt; 18 ms
IO=1;
Delay1 ();//20-40 us
Delay1 ();
Delay1 ();
Delay1 ();
Delay1 ();
}
Uchar receive_byte ()//????????????????
{
Uchar I, temp, count;
for(i=0; i<8; I++)
{
Temp=0;
Delay1 (); Delay1 (); Delay1 (); Delay1 ();
If (I/o==1) temp=1;
Count=2;
While ((IO) & amp; & Count++);
If (count==1) break;
Data_byte & lt; <=1;
Data_byte |=temp;
}
Return data_byte;
}
Void the receive ()//??????????
{
Uchar T_H T_L, R_H R_L, check, num_check;
Uchar count;
Start ().//????????
IO=1;
if(! IO)//??? DHT11????????
{

While ((IO) & amp; & Count++);
R_H=receive_byte ();
R_L=receive_byte ();
T_H=receive_byte ();
T_L=receive_byte ();
Check=receive_byte ();
IO=0;//??????????? 50 us
Delay1 (); Delay1 (); Delay1 (); Delay1 (); Delay1 ();
IO=1;
Num_check=R_H + R_L + T_H + T_L;
If (num_check=check)
{
RH=R_H;
RL=R_L;
TH=T_H;
TL=T_L;
Check=num_check;
}
}
}


Void showw ()//???????????
{
Lcd_init ();//???????
delay(10);

The display (0 x05, 'W');
The display (0 x06, 'e');
The display (0 x07, 'l');
The display (0 x08, 'c');
The display (0 x09, 'o');
The display (0 x0a, 'm');
The display (0 x0b, 'e');
Delay (250);//???????????
Delay (250);
Delay (250);


/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/*
The display (0 x40, ");
The display (0 x41, 'h');
The display (0 x42, 'e');

*/
}


nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related