1. Question requirements
Sometimes we need to know the historical data of the temperature measured by the temperature sensor over a period of time. The previous temperature sensor routine only displayed the data in real time on the LCD screen, and its historical data could not be viewed, so we used all the knowledge we learned before to complete this task.
First, we start with a simple concept and use the serial port to print out the current temperature value every second. In this way, all historical data can be seen in the computer window. However, the USB cable of our development board cannot leave the computer, so the temperature can only be measured by connecting it to the computer and observing the changes in the data in the computer window.
This time we use digital tube to display the real-time temperature. The data format printed by the serial port is as follows:
1st second: 10.2 degrees
2nd second: 15.7 degrees
3rd second: 7.6 degrees
4th second: 0.5 degrees
2.main.c test code
#include #include #include #include #include u8 flag1s = 0; void main() { u32 x=1; u8 str[13]; u16 temp; EA = 1; LED_Init(); Start18B20(); //Start DS18B20 TIM0_Init(1000,33); //Timing 1ms, 33 is fine-tuning to make the timing more accurate, each fine-tuning is determined by the content in the interrupt function ConfigUART(9600); while (1) { if (flag1s) //Update the temperature once a second { flag1s = 0; if( TEMP_CONV(&temp,str)==1 ) //The return value is 1, indicating that the temperature reading is successful { printf_str("第"); printf_num(x); x++; printf_str("Seconds:"); printf_str(str+temp_i); printf_str("degrees"); printf_rn(); //Carriage return and line feed temp_i=0; //The following is the content displayed by the digital tube LedBuff[0]=LedChar[str[4]-'0']; LedBuff[1]=0x7F; //Display decimal point LedBuff[2]=LedChar[str[2]-'0']; if(str[0]=='-') //temperature is less than 0 { if(str[1]=='0') { LedBuff[3]=0xBF; //The digital tube displays "-" LedBuff[4]=0xFF; } else { LedBuff[3]=LedChar[str[1]-'0']; LedBuff[4]=0xBF; //The digital tube displays "-" } } else //The temperature is greater than or equal to 0 { if(str[1]=='0')LedBuff[3]=0xFF; //The high bit does not display 0 else LedBuff[3]=LedChar[str[1]-'0']; if(str[0]=='0')LedBuff[4]=0xFF; //The high bit does not display 0 else LedBuff[4]=LedChar[str[0]-'0']; } } Start18B20(); //Restart the next conversion } } } void TIM0_IRQHandler() interrupt 1 { static u16 tmr1s = 0; TH0 = T0RH; //Reload the reload value TL0 = T0RL; tmr1s++; SEG_Scan(); if (tmr1s >= 1000) //Timer 1s { tmr1s = 0; flag1s= 1; } } void InterruptUART() interrupt 4 { if (RI) // Byte received { RI = 0; //Manually clear the receive interrupt flag } } 3. Serial port printing screenshot After I powered on the device, I deliberately blew hot air onto the temperature sensor on the development board, and the effect was great.
Previous article:51 single chip microcomputer - remote control servo
Next article:51 MCU - Simulate reversing radar alarm
- 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
- From probes to power supplies, Tektronix is leading the way in comprehensive innovation in power electronics testing
- Sn-doped CuO nanostructure-based ethanol gas sensor for real-time drunk driving detection in vehicles
- Design considerations for automotive battery wiring harness
- Do you know all the various motors commonly used in automotive electronics?
- What are the functions of the Internet of Vehicles? What are the uses and benefits of the Internet of Vehicles?
- Power Inverter - A critical safety system for electric vehicles
- Analysis of the information security mechanism of AUTOSAR, the automotive embedded software framework
- Brief Analysis of Automotive Ethernet Test Content and Test Methods
- How haptic technology can enhance driving safety
- Let’s talk about the “Three Musketeers” of radar in autonomous driving
- AT32F425-Evaluation Report-Keil Development Environment Construction 01
- MicroPython Hands-on (13) - RGB tri-color light on the control board
- [2022 Digi-Key Innovation Design Competition] Material Unboxing - STM32H745I-DISCO
- Today at 10:00 AM, live broadcast with prizes: ADI's smoke detector integrated solution based on ADPD188BI
- Transfer: Cortex-M development from the perspective of files (2) - Link files
- 【GD32E503 Review】——05.LCD Part 1: Testing the screen refresh speed
- Brief Analysis of RT-Thread System Equipment Framework
- Xintang: Secure In-System-Programming protects firmware burning security
- Transistor circuit problem
- [ST NUCLEO-H743ZI Review] + 5. LCD driver