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 #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
Previous article:Three methods of single chip microcomputer button
Next article:Speech synthesis module based on 51 single chip microcomputer
- Popular Resources
- Popular amplifiers
- Learn ARM development(16)
- Learn ARM development(17)
- Learn ARM development(18)
- Embedded system debugging simulation tool
- A small question that has been bothering me recently has finally been solved~~
- Learn ARM development (1)
- Learn ARM development (2)
- Learn ARM development (4)
- Learn ARM development (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- CGD and Qorvo to jointly revolutionize motor control solutions
- CGD and Qorvo to jointly revolutionize motor control solutions
- Keysight Technologies FieldFox handheld analyzer with VDI spread spectrum module to achieve millimeter wave analysis function
- Infineon's PASCO2V15 XENSIV PAS CO2 5V Sensor Now Available at Mouser for Accurate CO2 Level Measurement
- Advanced gameplay, Harting takes your PCB board connection to a new level!
- Advanced gameplay, Harting takes your PCB board connection to a new level!
- A new chapter in Great Wall Motors R&D: solid-state battery technology leads the future
- Naxin Micro provides full-scenario GaN driver IC solutions
- Interpreting Huawei’s new solid-state battery patent, will it challenge CATL in 2030?
- Are pure electric/plug-in hybrid vehicles going crazy? A Chinese company has launched the world's first -40℃ dischargeable hybrid battery that is not afraid of cold
- Application of Dacai UART screen in air detector
- [Serial] [Starlight Lightning STM32F407 Development Board] Chapter 13 FLASH Data Storage Experiment
- How do different power supplies affect the dynamic performance of the op amp?
- DSP28335 serial port interruption problem
- How to make an echo on atmel/AVR microcontroller Atmega 128? Is there any relevant information?
- I would like to ask about the error in the CD4093 schematic symbol in AD.
- Design of LED flash power supply based on XL6009 boost chip
- [2022 Digi-Key Innovation Design Competition] Material unboxing + ESP32S3-DevKitC-1 + MAix Bit + LICHEE RV D1
- What is an airplane stall? What happens if an airplane stalls at high speed?
- Dual-band transceiver for 1.3GHz and 2.3GHz bands