Intelligent control system of temperature and humidity in vegetable greenhouse based on 51 single chip microcomputer

Publisher:Harmonious88Latest update time:2020-08-25 Source: 51hei Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

Design of intelligent control system for temperature and humidity in vegetable greenhouse based on 51 single chip microcomputer Module usage: using dht11, 74hc595 digital tube module, relay module
Task

1) Control ventilation and heating based on the detected temperature and humidity information;

2) Using MCU, temperature and humidity sensors, relays, buttons, digital tubes, etc.;

3) Set the greenhouse temperature and humidity alarm value by pressing buttons;

4) Upload information to PC;

5) When the temperature or humidity exceeds the limit, the relay is used to control the small light state to simulate the occurrence of corresponding actions.

 

The microcontroller source program is as follows:

////////////////////////////////////////////////////////10.3 17:58/////////////////////////////////////////////////////////////////

#include //Include header file, generally no need to change, the header file contains the definition of special function registers

#include

#include

#define uchar unsigned char

#define uint unsigned int       

sbit RS = P1^0; //define port

sbit RW = P1^1;

sbit EN = P2^5;

sbit DU = P2^0;

sbit WE = P2^1;

sbit Data = P3^6; //define data line



uchar rec_dat[19]; ​​//Received data array for display


#define RS_CLR RS=0

#define RS_SET RS=1


#define RW_CLR RW=0

#define RW_SET RW=1


#define EN_CLR EN=0

#define EN_SET EN=1


#define DataPort P0



void cmg88() //Turn off the digital tube, dot matrix function

{

DU=1;  

P0=0X00;

DU=0;

}

/*------------------------------------------------

uS delay function, with input parameter unsigned char t, no return value

unsigned char is used to define an unsigned character variable, whose value range is

0~255 Here we use a 12M crystal oscillator. Please use assembly for accurate delay. Approximate delay

The length is as follows: T=tx2+5 uS

------------------------------------------------*/

void DelayUs2x(unsigned char t)

{   

while(--t);

}

/*------------------------------------------------

mS delay function, with input parameter unsigned char t, no return value

unsigned char is used to define an unsigned character variable, whose value range is

0~255 Here we use a 12M crystal oscillator. Please use assembly code for accurate delay.

------------------------------------------------*/

void DelayMs(unsigned char t)

{

     

while(t--)

{

     //About 1mS delay

     DelayUs2x(245);

         DelayUs2x(245);

}

}


// Busy detection function

bit LCD_Check_Busy(void)

{

DataPort = 0xFF;

RS_CLR;

RW_SET;

EN_CLR;

_nop_();

EN_SET;

return (bit)(DataPort & 0x80);

}

// Write command function

void LCD_Write_Com(unsigned char com)

{  

while(LCD_Check_Busy()); //Wait if busy

RS_CLR;

RW_CLR;

EN_SET;

DataPort=com;

_nop_();

EN_CLR;

}

// Write data function

void LCD_Write_Data(unsigned char Data)

{

while(LCD_Check_Busy()); //Wait if busy

RS_SET;

RW_CLR;

EN_SET;

DataPort = Data;

_nop_();

EN_CLR;

}


// Clear screen function

void LCD_Clear(void)

{

LCD_Write_Com(0x01);

DelayMs(5);

}

// Write string function

void LCD_Write_String(unsigned char x,unsigned char y,unsigned char *s)

{     

if (y == 0)

        {     

         LCD_Write_Com(0x80 + x); // indicates the first line

        }

else

        {      

        LCD_Write_Com(0xC0 + x); // indicates the second line

        }        

while (*s)

        {     

LCD_Write_Data( *s);     

s++;     

        }

}

   // Write character function

void LCD_Write_Char(unsigned char x,unsigned char y,unsigned char Data)

{     

if (y == 0)

        {     

        LCD_Write_Com(0x80 + x);     

        }   

else

        {     

        LCD_Write_Com(0xC0 + x);     

        }        

LCD_Write_Data( Data);  

}

// Initialization function

void LCD_Init(void)

{

   LCD_Write_Com(0x38); /*Display mode setting*/

   DelayMs(5);

   LCD_Write_Com(0x38);

   DelayMs(5);

   LCD_Write_Com(0x38);

   DelayMs(5);

   LCD_Write_Com(0x38);  

   LCD_Write_Com(0x08); /*Display off*/

   LCD_Write_Com(0x01); /*Clear the screen*/

   LCD_Write_Com(0x06); /*Display cursor movement settings*/

   DelayMs(5);

   LCD_Write_Com(0x0C); /*Display on and cursor setting*/

   }

   


/*------------------------------------------------

              DHT11 delay function

------------------------------------------------*/

void DHT11_delay_us(uchar n)

{

    while(--n);

}


void DHT11_delay_ms(uint z)

{

   uint i,j;

   for(i=z;i>0;i--)

      for(j=110;j>0;j--);

}

/*------------------------------------------------

              DHT11 Start Signal

------------------------------------------------*/

void DHT11_start()

{

   Data=1;

   DHT11_delay_us(2);

   Data=0;

   DHT11_delay_ms(20); //delay more than 18ms

   Data=1;

   DHT11_delay_us(30);

}

// Receive eight bits of binary

uchar DHT11_rec_byte() //Receive a byte

{

   uchar i,dat=0;

  for(i=0;i<8;i++) //Receive 8 bits of data from high to low

   {         

      while(!Data); ////Wait for 50us low level to pass

      DHT11_delay_us(8); // Delay 60us, if it is still high, the data is 1, otherwise it is 0

      dat<<=1; // Shift to receive 8-bit data correctly, shift directly when the data is 0

      if(Data==1) //When data is 1, add 1 to dat to receive data 1

         dat+=1;

      while(Data); //Wait for the data line to be pulled low   

    }  

    return dat;

}

// Receive 40 bits of data


void DHT11_receive() //Receive 40 bits of data

{

    uchar R_H,R_L,T_H,T_L,RH,RL,TH,TL,revise;

    DHT11_start();


    if(Data==0)

    {

       

        while(Data==0); //Wait for high     

               

        DHT11_delay_us(40); //Delay 80us after pulling high

        R_H=DHT11_rec_byte(); //Receive high eight bits of humidity  

        R_L=DHT11_rec_byte(); //Receive the lower eight bits of humidity  

        T_H=DHT11_rec_byte(); //Receive high eight bits of temperature  

        T_L=DHT11_rec_byte(); //Receive the lower eight bits of temperature

        revise=DHT11_rec_byte(); //Receive correction bit

                         

        DHT11_delay_us(25); //End


        if((R_H+R_L+T_H+T_L)==revise) //correction

        {

            RH=R_H;

            RL=R_L;

            TH=T_H;

            TL=T_L;

        }

        /*Data processing, convenient display*/

        rec_dat[0]='0'+(RH/10);

        rec_dat[1]='0'+(RH%10);

                rec_dat[2] = ' ';

                rec_dat[3] = 'R' ;

                rec_dat[4] = 'H';

        rec_dat[5]=' ';

        rec_dat[6]=' ';

        rec_dat[7]=' ';

        rec_dat[8]=' ';

        rec_dat[9]='0'+(TH/10);

        rec_dat[10]='0'+(TH%10);

                rec_dat[11] = ' ';

                rec_dat[12] = 'C';

                rec_dat[13] = ' ' ;

        rec_dat[14]=' ';

                rec_dat[15] =(RH/10);

                rec_dat[16] =(RH%10);

                rec_dat[17] =(TH/10);

        rec_dat[18]=(TH%10);

    }

}

/////////////////Digital Tube///////////////////////////////////////////////


  

unsigned char code fseg[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};

unsigned char code segbit[]={0x80,0x40,0x20,0x10,0x08,0x04,0x02,0x01};

unsigned char disbuf[8]={0,0,0,0,0,0,0,0};

unsigned char code LED_0F[]; //LED font table


sbit DIO = P1^0; //Serial data input

sbit rclck = P1^1; //Clock pulse signal——rising edge is valid

sbit SCLK = P1^2; //Input signal————Rising edge is valid


//-----------------------------------------------------------------------------

// Global variables

uchar LED[8]; //8-bit display buffer for LED

  



unsigned char code LED_0F[] =

{// 0 1 2 3 4 5 6 7 8 9 A b C d E F -

        0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90,0x8C,0xBF,0xC6,0xA1,0x86,0xFF,0xbf

};


void LED_OUT(uchar X)

{

        uchar i;

        for(i=8;i>=1;i--)

        {

                if (X&0x80) DIO=1; else DIO=0;

                X<<=1;

                SCLK = 0;

                SCLK = 1;

        }

}  


void LED8_Display (void)

{

        unsigned char code *led_table; // table pointer

        uchar i;

        // Display the first

        led_table = LED_0F + LED[0];

        i = *led_table;


        LED_OUT(i);                       

        LED_OUT(0x01);               


        rclck = 0;

        rclck = 1;

        //Display the second digit

        led_table = LED_0F + LED[1];

        i = *led_table;


        LED_OUT(i);               

        LED_OUT(0x02);               


        rclck = 0;

        rclck = 1;

        //Display the 3rd digit

        led_table = LED_0F + LED[2];

        i = *led_table;


        LED_OUT(i);                       

        LED_OUT(0x04);       


        rclck = 0;

        rclck = 1;

        //Display the 4th digit

        led_table = LED_0F + LED[3];

        i = *led_table;


        LED_OUT(i);                       

        LED_OUT(0x08);               


        rclck = 0;

        rclck = 1;

                led_table = LED_0F + LED[4];

        i = *led_table;

        LED_OUT(i);                       

        LED_OUT(0x10);       

        rclck = 0;

        rclck = 1;         

                 

                //Display the 6th digit

        led_table = LED_0F + LED[5];

        i = *led_table;


        LED_OUT(i);                       

        LED_OUT(0x20);       


        rclck = 0;

        rclck = 1;

                 //Display the 7th digit

        led_table = LED_0F + LED[6];

        i = *led_table;


        LED_OUT(i);                       

        LED_OUT(0x40);       


        rclck = 0;

        rclck = 1;         

                         //Display the 8th digit

        led_table = LED_0F + LED[7];

        i = *led_table;


        LED_OUT(i);               

        LED_OUT(0x80);       


        rclck = 0;

        rclck = 1;

        }



void LED2_Display (uchar *wei)

{

        unsigned char code *led_table; // table pointer

        uchar i;

if(wei==1)

{

        // Display the first

        led_table = LED_0F + LED[0];

        i = *led_table;


        LED_OUT(i);                       

        LED_OUT(0x01);               


        rclck = 0;

        rclck = 1;

        //Display the second digit

        led_table = LED_0F + LED[1];

        i = *led_table;


        LED_OUT(i);               

        LED_OUT(0x02);               


        rclck = 0;

        rclck = 1;

}

if(wei==2)

{

        //Display the 3rd digit

        led_table = LED_0F + LED[2];

        i = *led_table;


        LED_OUT(i);                       

        LED_OUT(0x04);       


        rclck = 0;

        rclck = 1;

        //Display the 4th digit

[1] [2] [3]
Reference address:Intelligent control system of temperature and humidity in vegetable greenhouse based on 51 single chip microcomputer

Previous article:Three methods of single chip microcomputer button
Next article:Speech synthesis module based on 51 single chip microcomputer

Latest Microcontroller Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号