I added oled here to display temperature and humidity, using STC15, dht11 modules
#include #include "intrins.h" // used to provide _nop_(); function #include "OLED_Contrul_Hygrothermograph.c" //OLED control function sbit YLED=P3^1; sbit RLED=P3^0; sbit DHT=P3^5; //DHT11 module unsigned int Temperature[3]={1,1,1}; //The first two digits are the integer part, and the last digit is the decimal part unsigned int Humidity[2]={1,1}; //The returned humidity data only has the integer part unsigned char Data_Receive[5]; /*############################################################################################## Design name: Hygrothermograph based on DHT11 Designer: Qinghe Platform: STC15F104W Hardware parts Display: OLED12864 is used to display temperature and humidity The measurement uses the DHT11 module, and the module information is as follows: ASATR ----- NA:DHT11 OC:3.3-5.5V U1:5-95%RH U2:-20-60℃ U3:±5%RH±2℃ SN:A1712882A To ensure accurate delay, the crystal oscillator is set to 12MHz I borrowed some programs from http://www.51hei.com/bbs/dpj-38067-1.html, and I would like to express my gratitude ##############################################################################################*/ void Delay30us()//@12.000MHz { unsigned char i; i=87; while(--i); } void Delay20ms()//@12.000MHz { unsigned char i,j,k; i=1; j=234; k=113; do { do { while(--k); }while(--j); }while(--i); } void Delay1s()//@12.000MHz { unsigned char i,j,k; i=46; j=153; k=245; do { do { while(--k); }while(--j); }while(--i); } void OLED_Display() //OLED display driver function { OLED_DataDisplay_T(56,4,Temperature); //Display temperature at the specified position OLED_DataDisplay_H(56,6,Humidity); //Display humidity at the specified location } void DHT_Collect()//Temperature collection function { unsigned char i,j;//for loop variable unsigned char t; //Timeout judgment unsigned char dat8=0; //8 bits of data read at a time, need to be read 5 times unsigned int CheckValue=0; //Checksum DHT=0; //Host sends start signal Delay20ms(); //Host pulls the bus down for at least 18ms DHT=1; //Host pulls up the bus for 20~40us Delay30us(); t=80; //Set the timeout waiting time while(DHT&&t--); //Wait for DHT11 to pull down the bus if(t==0)//timeout { DHT=1; } t=250; //Set the timeout waiting time while(!DHT&&t--); //Wait for DHT11 to pull up the bus if(t==0)//timeout { DHT=1; } t=250; //Set the timeout waiting time while(DHT&&t--); //Wait for DHT11 to pull down the bus if(t==0)//timeout { DHT=1; } for(j=0;j<5;j++) //5 times reading { for(i=0;i<8;i++) // 1 time 8 bits { //Wait for 50us to start the time slot t=150; //Set the timeout waiting time while(!DHT&&t--); //Wait for DHT11 to pull up the bus if(t==0)//timeout { DHT=1; } t=0; //Record time clear while(DHT&&++t); //Wait and record the duration of high level dat8<<=1; if(t>30) //High level lasts longer (70us) dat8+=1; //transmission value is 1 } Data_Receive[j]=dat8; } Delay30us(); //Wait for DHT11 to pull down for 50us Delay30us(); DHT=1; for(i=0;i<4;i++) { CheckValue+=Data_Receive[i]; //Calculate the check value } if((unsigned char)CheckValue==Data_Receive[4])//比对 { Temperature[0]=Data_Receive[2]/10; Temperature[1]=Data_Receive[2]%10; Temperature[2]=Data_Receive[3]%10; Humidity[0]=Data_Receive[0]/10; Humidity[1]=Data_Receive[0]%10; } } void sys_init()//system initialization function { YLED=1; RLED=1; OLED_Init(); //OLED initialization OLED_CLS(); //Clear screen OLED_FormTitle(0,0); //Display title text Linyar Lab. OLED_FormName(0,2); //Display Hygrothermograph name OLED_FormLine(0,3); //Display a horizontal line OLED_FormTemp(8,4); //Display temperature text OLED_FormHumi(16,6); //Display humidity text OLED_AnyChar_16X16(96,4,TempChar); //Display the Celsius degree ℃ character at row 4 (each row is 16 pixels high) and column 96 pixel position OLED_AnyChar_8X16(88,6,HumiChar); //Display the percent sign % at row 6 (each row is 16 pixels high) and column 88 pixels OLED_AnyChar_8X16(72,4,PointChar); //Display the colon character at row 4 (each row is 16 pixels high) and column 72 pixels } void main() { P3M0=0X00; P3M1=0X00; sys_init(); while(1) { DHT_Collect(); //DHT11 data collection YLED=1;RLED=0;//Light state conversion OLED_Display(); //OLED display function RLED=1;YLED=0;//Light state conversion Delay1s(); Delay1s(); //Note: A long delay is required, otherwise it will read 0 } }
Previous article:51 single chip microcomputer intelligent car ultrasonic obstacle avoidance experiment
Next article:51 MCU RS485 program source code and proteus simulation diagram
- Popular Resources
- Popular amplifiers
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
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- How large a fifo capacity can ep4ce6 achieve?
- 【TI recommended course】#Motor control voltage and current sampling solution#
- Allwinner heterogeneous multi-core AI intelligent vision V853 development board evaluation - separate compilation and testing of V853 SDK LVGL routines
- [Hua Diao Experience] Xingkong Board & Beetle ESP32-C3
- Low frequency power amplifier
- "Domestic Chip Exchange" is launched! How to do it is up to you!
- [ESP32-Audio-Kit Audio Development Board] - 5: Run "esp-adf" flash on Ubuntu 20.04
- Are the design formulas for a push-pull transformer correct?
- Do you know the function of OPA?
- [RVB2601 Creative Application Development] Handheld Game Console (3) Flying Bird