1 Introduction
In traditional temperature measurement systems, analog temperature sensors are generally used. One of the common characteristics of commonly used analog temperature sensors is that the output is analog, so it must be converted by A/D in the measurement circuit to become a digital quantity that can be processed by the computer. Digital temperature sensors integrate multiple links of the process of converting non-electrical analog quantities to digital signals on a single chip, realizing the digitization of temperature values at the measurement point, effectively solving the problems of traditional temperature sensors with complex peripheral circuits and poor anti-interference ability, and reducing the requirements for the system.
The system uses Atmel's ATmega8L microcontroller as the control center, uses the DS18B20 single-bus digital temperature sensor for temperature measurement, and uses a 1602 character LCD as the display output of the temperature value. The CodeVision AVR C Compiler is used for programming. The compiler software comes with a device library function file, which saves the step of writing device drivers and brings great convenience to program writing.
2 Hardware Design
Figure 1 shows the system circuit diagram. The PB0 port of the ATmega8L microcontroller is connected to the DS18B20; the PD port is connected to the 1602 LCD. The DS18B20 uses the source end connection mode, and the LCD uses the 4-bit bus mode. Among them, the connection mode of the LCD display module depends on the setting of the code wizard avr automatic program generator of the programming software Code Vision AVR C Compiler. In this way, the library function can be directly called to realize the operation of the LCD display.
2.1 ATmega 8L microcontroller
Atmel's EEPROM electrically erasable technology and flash memory technology are the most eye-catching high-quality and high-reliability production technologies. In the field of CMOS device production, Atmel's design level, production process and packaging technology have always been in the world's leading position. These technologies make the microcontroller also have excellent quality and have obvious advantages in structure, performance, etc. [page]
The features of the ATmega8L microcontroller are: 8 KB of in-system programmable Flash, 512 bytes of EEPROM, 1 KB of SRAM, 32 general-purpose I/O lines, 32 general-purpose working registers, 3 flexible timers/counters with compare modes, internal/external interrupts, programmable serial USART, byte-oriented two-wire serial interface, 10-bit 6-channel A/D converter, programmable watchdog timer with on-chip oscillator, an SPI serial port, and 5 power saving modes that can be selected by software.
2.2 DS18B20 Digital Temperature Sensor
1-Wire is a proprietary technology of Dallas Corporation. Different from most current standard serial data communication methods, such as SPI/I2C/MICROWIRE, it uses a single signal line to transmit both clock and data, and the data transmission is bidirectional. Therefore, it has many advantages such as saving I/O port line resources, simple structure, low cost, and easy bus expansion and maintenance.
The measurement temperature range of DS18B20 is -55~+125℃. The output temperature data of this temperature sensor can be calibrated with Celsius, and the temperature value can be calculated using a lookup table or conversion rule. The temperature data storage format in the temperature register is two units of a 16-bit sign extension, and the temperature register format is shown in Figure 2. The sign bit S indicates the positive or negative temperature. S=0 is positive; S=1 is negative. When the DS18B20 is configured with 12-bit resolution (the measurement accuracy is 0.062 5℃), all bit data of the temperature register are valid; when the DS181320 is configured with 11-bit resolution (the measurement accuracy is 0.125℃), bit0 is undefined; when the DS181320 is configured with 10-bit resolution (the measurement accuracy is 0.25℃), bit0 and bit1 are undefined; when the DS181320 is configured with 9-bit resolution (the measurement accuracy is ..5℃), bit0~bit2 are undefined.
2.3 1602 LCD display
The 1602 LCD uses OCM2×16A produced by Jinpeng Electronics Co., Ltd. The character dot matrix series module is a type of dot matrix LCD display module specially used to display letters, numbers, symbols, etc. It is divided into 4-bit and 8-bit data transmission modes, provides a 5×7 dot matrix + cursor display mode, and is equipped with a display data buffer DDRAM, a character generator CGROM and a character generator CGRAM. CGRAM can be used to store the font data of up to 8 custom 5×8 dot matrix graphic characters, and provides rich instructions such as setting, clearing display, cursor return to origin, display on/off, cursor on/off, display character flashing, cursor shift, display shift, etc. In addition, an internal power-on automatic reset circuit is also provided. When the external power supply voltage exceeds +4.5 V, the module can be automatically initialized and the module is set to the default display working state.
3. Software Design
3.1 Code Vision AVR C Compiler
Code Vision AVR is a C cross compiler with an integrated development environment and automatic program generator designed for Atmel's AVR series of microcontrollers. The compiled coff object file can be used for C source code level debugging, or it can be debugged using the AVR Studio debugger.
In addition to the standard C library functions, Code Vision AVR C Compiler also has library functions for other devices, such as alphanumeric LCD display modules, Philips I2C bus, NS's LM75 temperature sensor, Philips' PCF8563 and PCF8583, Dallas's DS1302 and DS1307 real-time clock devices, and DS1820/DS1822 temperature sensors. CodeVision AVR also includes the Code Wizard AVR program automatic generator, which can generate the initialization program in just a few minutes by adding the header files of the relevant devices, and can call the function functions contained in the header files as needed to realize the operation of peripheral devices. [page]
3.2 Program Design
Figure 3 shows the program flow. When writing a program, you must first declare which ports communicate with the peripheral devices. For example, the connection between the DS18B20 single-wire bus and the microcontroller PB0 port is declared as follows:
Then, the function header file must be included in the program to call the function in the header file. The header file is stored in the "..\\INC" directory. The function used by the temperature measurement system is in the three header files "ds18b20.h", "1WIRE.h", and "LCD.h".
When calling the function to operate the DS18B20, since each DS18B20 has a unique code (64-bit product serial number), in the multi-point temperature measurement and control system, the code is the basis for identifying and operating the DS18B20. Whether reading or selecting a sensor to operate, the host must send a 64-bit code. If there is only one DS18B20, there is no need for a ROM code, and the pointer addr should be set to NULL (0). If there are multiple devices, the ROM code must be read first to identify each device, and then the address of the required device can be matched through the ROM code when calling. The program first initializes the I/O port, and then uses the function floatds18b20_temperature (unsigned char*addr) in the header file ds18b20.h to read the temperature value. From the function definition, it can be seen that the return value of the function is floating-point data, and integer division and remainder operations are required when extracting the value of each bit. Since floating-point data cannot be divided and remaindered, it needs to be converted into long integer data first. When the floating point data is converted to long integer data, the value after the decimal point will be lost. In order to keep the value after the decimal point from being lost after conversion to long integer, the floating point data is multiplied by 1 000 at the same time, so that the values of hundreds, tens, units, tenths, percentiles, and thousandths can be separated. The values of each separated digit are converted into LCD character codes respectively, and the LCD character codes can be transmitted to the LCD and displayed.
4 Experimental results
In order to detect the accuracy of the measurement system, a temperature measurement experiment was carried out. As the platinum resistance temperature sensor has high precision, good stability and a wide range of application temperature, it is widely used as a common temperature detector, not only in industrial temperature measurement, but also made into various standard thermometers. Here, PT1000 is used as the standard thermometer. DS18B20 and PT1000 are bundled together and put into a high and low temperature box for testing. By changing the temperature of the high and low temperature box, the temperature value is recorded on the LCD display after the temperature in the box stabilizes; at the same time, a high-precision multimeter is used to measure the specific resistance value of the PT1000 platinum resistor, and then the temperature value is calculated according to the PT1000 graduation table. The error of the system can be calculated by comparing the two values. Table 1 gives the test results. It can be seen that the temperature measured by the DS18B20 and the PT1000 platinum resistors is consistent with each other. This shows that the measurement of the temperature measurement system is accurate and reliable.
5 Conclusion
The temperature measurement system has a simple hardware design and makes full use of the library functions of the compiler CodeVisionAVR C Compiler, eliminating the trouble of writing drivers and greatly shortening the development cycle. It also has strong anti-interference ability, easy expansion, low cost and applicability. It can be expanded for multi-point measurement and only occupies one I/O port. It has wide application value in temperature measurement systems.
Previous article:AVR analog-to-digital (AD) conversion program
Next article:Atmega128 serial port UART 0/1 test code
Recommended ReadingLatest update time:2024-11-16 17:36
- Popular Resources
- Popular amplifiers
- MCU C language programming and Proteus simulation technology (Xu Aijun)
- 100 Examples of Microcontroller C Language Applications (with CD-ROM, 3rd Edition) (Wang Huiliang, Wang Dongfeng, Dong Guanqiang)
- Single-chip microcomputer technology and application - electronic circuit design, simulation and production (edited by Zhou Runjing)
- Principles and Applications of Single Chip Microcomputers and C51 Programming (3rd Edition) (Xie Weicheng, Yang Jiaguo)
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
- [Hua Diao Experience] 06 Building a Xingkong board development environment - Thonny programming
- The most comprehensive collection of circuit postgraduate entrance examination questions and tutorials, a benefit for postgraduate entrance examination candidates!
- GD32E231C_START ADC code evaluation
- TMS320F28335 project development record 11_28335 storage system
- Things you must know about Gallium Nitride (GaN): Technology (Part 2)!
- MC34063A step-down circuit chip cooling
- SinlinxA33 Simple QT control LED (io control)
- Can CycloneIII FPGA lock JTAG?
- "Playing with the board" + Yu Zhennan's STM32 development board experiment 3
- 【NUCLEO-L552ZE Review】2. Resources