Function:
Design a temperature alarm system that can set the upper and lower limits of the temperature. When the set value is reached, the buzzer will sound; the button setting has the functions of setting, confirming, canceling, reducing and increasing, and LCD1602 will display relevant temperature information in real time.
Setting interface:
When the temperature exceeds the set value, the buzzer sounds:
The temperature exceeds the set value and the buzzer sounds: The temperature exceeds the set value.
When the temperature is lower than the set value, the buzzer sounds:
Part of the program:
#include #include "SETTEM.h" //Set the upper and lower limit header files for alarms #include "Lcd1602.h" //LCD display module function header file #include "DS18B20.h" //DS18B02 module function header file #include "IntToChar.h" //Header file that stores integers converted to strings #include "Alarm.h" //Alarm function header file bit flag1s = 0; //1s timing flag unsigned char T0RH = 0; //High byte of T0 reload value unsigned char T0RL = 0; //low byte of T0 reload value int key=0; char Hint1[]={"Current temperature"}; void ConfigTimer0(unsigned int ms); void main() { bit res; int temp; //The current temperature value read int intT, decT; //The integer and decimal parts of the temperature value unsigned char len; unsigned char str[12]; EA = 1; //Enable total interrupt ConfigTimer0(10); //T0 timing 10ms Start18B20(); //Start DS18B20 InitLcd1602(); //Initialize LCD ConfigInt0(); //Set the temperature while (1) { if (flag1s) //Update temperature every second { flag1s = 0; res = Get18B20Temp(&temp); //Read the current temperature if (res) //When reading is successful, refresh the current temperature display { intT = temp >> 4; //Separate the integer part of the temperature value decT = temp & 0xF; //Separate the decimal part of the temperature value len = IntToString(str, intT); //Convert the integer part to a string str[len++] = '.'; //Add decimal point decT = (decT*10) / 16; //Convert the decimal part of binary to 1 decimal digit str[len++] = decT + '0'; //Convert decimal digits to ASCII characters str[len++] = key + '0'; while (len < 6) //Use spaces to complete to 6 characters in length { str[len++] = ' '; } str[len] = ''; //Add string terminator LcdShowStr(0, 0, Hint1); //The prompt is displayed on the LCD screen LcdShowStr(0, 1, str); //The temperature is displayed on the LCD screen } else //When reading fails, an error message is prompted { LcdShowStr(0, 0, "error!"); } Start18B20(); //Restart the next conversion Alarm((float)temp*0.0625,Htem,Ltem); } } }
Previous article:Car reversing anti-collision alarm system based on 51 microcontroller
Next article:Design of fingerprint access control based on microcontroller
Recommended ReadingLatest update time:2024-11-16 13:24
- Popular Resources
- Popular amplifiers
- Single-chip microcomputer C language programming and simulation
- 100 Examples of Microcontroller C Language Applications (with CD-ROM, 3rd Edition) (Wang Huiliang, Wang Dongfeng, Dong Guanqiang)
- Principles and Applications of Single Chip Microcomputers and C51 Programming (3rd Edition) (Xie Weicheng, Yang Jiaguo)
- stm32+lcd1602 example
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- 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
- Please tell me why the 5V can't be turned off in this picture
- Transimpedance
- Allegro display problem
- Can Tantalum Capacitors Replace MLCC?
- Design of USB interface based on DSP
- Power relay contacts sticking
- Teach you step by step how to operate a multimeter!
- 【ST NUCLEO-G071RB Review】GPIO
- Basic knowledge of base station antennas and network applications
- Photos + Our product board