Temperature Measurement System Based on AVR Microcontroller

Publisher:HeavenlyMelodyLatest update time:2013-12-11 Source: eefocus Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

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.

Reference address:Temperature Measurement System Based on AVR Microcontroller

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

MCU - ds18b20 - Code
#include      #include "../delay/delay.h"     #include "lcd.h"          /*====================================================                     Determine write command/data function    =====================================================*/     void lcd_write(unsigned char byte, unsigned char flag)     {  
[Microcontroller]
DS18B20 reads temperature and displays it - assembly program
* Program effect: Read the temperature value through DS18B20 and display the corresponding temperature value The program focuses on understanding the timing and delay time */ DS18DQ EQU P1.3 //P1.3 is equivalent to DS18DQ, which is easy to understand SPEAKER EQU P2.0 //Drive the buzzer TEM
[Microcontroller]
Microcontroller tutorial and learning LCD1602 display DS18B20 temperature experiment
#include #include intrins.h typedef   unsigned int uint; typedef unsigned char   uchar; sbit LCD_RS=P2^0; sbit LCD_RW=P2^1; sbit LCD_EN=P2^2; sbit DQ=P3^4; uchar Temp_Value ={0x00,0x00}; uchar Temp=0; uchar Display_Digit ={0,0,0,0}; bit DS18B20_IS_OK=1; uchar code df_tab ={0,1,1,2,3,3,4,4,5,6,6,7,8,8,9,9}
[Microcontroller]
stc12c5A60s2 uses ds18b20 to measure temperature
//Temperature display program ==LED display, accuracy 0.1 degrees Celsius //Crystal oscillator: 12M //MCU: stc12c5a60s2 1T /********************************************** Jumper settings: default Note: Do not insert ds18b20 in reverse, there is a risk of explosion and burns, the direction is that the plane of ds18
[Microcontroller]
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号