Temperature Measurement System Based on 51 Single Chip Microcomputer

Publisher:雅致书香Latest update time:2012-01-03 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
Introduction
The application of single-chip microcomputers in electronic products has become more and more extensive, and they are also used in temperature detection and temperature control in many electronic products. For this reason, the author designed a temperature measurement system based on atmel's AT89C2051 in this article. This is a low-cost temperature detection circuit that uses the redundant I/O ports of the single-chip microcomputer. The circuit is very simple, easy to implement, and suitable for almost all types of single-chip microcomputers.

I. System hardware design
The hardware structure of the system is shown in Figure 1.


1.1 Data acquisition
The data acquisition circuit is shown in Figure 2. The temperature sensor DS18B20 collects the real-time temperature of the controlled object and provides it to the P3.2 port of AT89C2051 as data input. In this design, the object we control is the room temperature. Of course, as an improvement, we can separate the sensor from the circuit board and connect them by data lines for communication, which is convenient for measuring multiple objects.

DS18B20 is a one-line digital temperature sensor produced by DALLAS, with a 3-pin TO-92 small package; the temperature measurement range is -55℃~+125℃, and it can be programmed to 9-bit~12-bit A/D conversion accuracy, and the temperature measurement resolution can reach 0.0625℃. The measured temperature is serially output in a 16-bit digital quantity with sign extension, supporting a voltage range of 3V~5.5V, making the system design more flexible and convenient; its working power supply can be introduced at the remote end or generated by parasitic power supply; multiple DS18B20 can be connected in parallel to 3 or 2 lines, and the CPU only needs one port line to communicate with many DS18B20, occupying fewer ports of the microprocessor, which can save a lot of leads and logic circuits. The above features make DS18B20 very suitable for long-distance multi-point temperature detection systems. The resolution setting and the alarm temperature set by the user are stored in the EEPROM and are still saved after power failure. DS18B20 allows more choices for voltage and characteristics, allowing us to build an economical temperature measurement system that suits us. As shown in Figure 2, the 2nd pin DQ of DS18B20 is the digital signal input/output terminal; the 1st pin GND is the power ground; the 3rd pin VDD is the external power supply input terminal.

AT89C2051 (hereinafter referred to as 2051) is an 8051 compatible single-chip microcontroller, which is fully compatible with Intel's MCS-51. It has a built-in 2K programmable Flash storage and 128B bytes of data storage space. It can directly drive LEDs. It is exactly the same as 8051 and has 15 programmable I/O points, namely P1 port and P3 port (less P3.6).

1.2 Interface Circuit

Figure 2 Connection diagram of single-chip microcomputer 2051 and temperature sensor DS18B20

The interface circuit is composed of ATMEL's 2051 single-chip microcomputer, ULN2003 Darlington chip, 4511BCD decoder, serial EEPROM24C16 (to save system parameters), MAX232, digital tube and peripheral circuits. The single-chip microcomputer outputs control signals from P1.0 to P1.7 ports in parallel communication mode, decodes through 4511BCD decoder, and uses two common cathode LEDs to statically display the tens and ones of the temperature.

Serial EEPROM24C16 is a standard I2C specification and can be read and written with only two pins. Since P1 of single-chip microcomputer 2051 is a bidirectional I/O port, we use P1 port as an output port in our design. As shown in Figure 2, P1.7 is connected to the 6th pin of 24C16 as a serial clock output signal, and P1.6 is connected to the 5th pin of 24C16 as a serial data output. P1.4 and P1.5 are used as the bit selection signal control of the two digital tubes. When P1.4=1, the first digital tube (ones place) is selected; when P1.5=1, the second digital tube (tens place) is selected. The output signals of P1.0~P1.3 are connected to the decoder 4511 as the display of the digital tube. In addition, since the P3 port of the single-chip microcomputer 2051 has special functions, P3.0 (RXD) is a serial input port, P3.1 (TXD) is a serial output port, P3.2 (INTO) is an external interrupt 0, P3.3 (INT1) is an external interrupt 1, P3.4 (T0) is an external timing/counting input point, and P3.5 (T1) is an external timing/counting input point. As shown in Figure 2, P3.0 and P3.1 are used as interfaces for serial communication with MAX232; P3.2 and P3.3 are used as interrupt signal interfaces; P3.4 and P3.5 are used as external timing/counting input points. P3.7 is used as a pulse output to control the on and off of the light-emitting diode.

Since the common cathode LED digital tube is used in the circuit, a Darlington circuit ULN2003 is added when designing the circuit to amplify the signal and generate a large enough current to drive the digital tube display. Since 4511 can only perform BCD decimal decoding and can only decode from 0 to 9, here we use 4511 to decode and output the temperature we need.

1.3 Alarm Circuit Introduction

Figure 3 Temperature display connection diagram on seven-segment digital tube

The alarm circuit designed in this article is relatively simple, consisting of a self-oscillating buzzer (as long as the voltage across the buzzer exceeds 3V, the buzzer will keep beeping) and a light-emitting diode (as shown in Figure 3). In this design, the buzzer is controlled by the ULN2003 current amplifier IC. When the required temperature reaches a certain upper or lower limit (in this article, we set the upper limit temperature to 45℃ and the lower limit temperature to 5℃), the alarm circuit starts working. The main program design is as follows:
main() //Main function
{unsigned char i=0;
unsigned int m,n;
while(1)
{i=ReadTemperature(); //Read temperature}
if(i>0 && i<=10) //If the temperature is between 0 and 10 degrees, directly assign values ​​to the seven-segment digital tube
{P1=designP1[i];}
else //If the temperature is greater than 10 degrees
{m=i%10; //First assign values
​​D1=1;
D2=0;
P1=designP1[m] to the first seven-segment digital tube; n=i/10; //Then assign values ​​D1=0; D2=1; P1=designP1[n]
to the second seven-segment digital tube ; if(n>=4&&m>=5)%%(m<=5)//Judge the temperature range. If it is greater than 45 or less than 5 degrees, the buzzer sounds and the LED flashes { int a,b; Q1=1;//Buzzer soundsfor (a=0;a<1000;a++)//LED flashesfor (b=0;b<1000;b++) Q2=1; for(a=0;a<1000;a++) for(b=0;b<1000;b++) Q2=0;}}}












2. System software design

Figure 4 System program flow chart

2.1 System program flow chart
The system program flow chart is shown in Figure 4.

2.2 Temperature software design

The first-line working protocol flow of DS18B20 is: initialization → ROM operation instruction → memory operation instruction → data transmission. Its working sequence includes initialization sequence, write sequence and read sequence. Therefore, the host must go through three steps to control DS18B20 to complete temperature conversion: reset DS18B20 before each reading and writing, send a ROM instruction after the reset is successful, and finally send RAM instruction, so that the DS18B20 can perform the predetermined operation. Reset requires the main CPU to pull down the data line for 500 microseconds and then release it. After receiving the signal, DS18B20 waits for about 16 to 60 microseconds, and then sends a 60 to 240 microsecond low pulse. The main CPU receives this signal to indicate that the reset is successful. The main functions of the program are as follows:

(1) Initialization function
//Read a byte
functionReadOneChar(void)
{unsigned char i=0;
unsigned char dat = 0;
for (i=8;i>0;i--)
{ DQ = 0; // Give pulse signaldat
>>=1;
DQ = 1; // Give pulse signalif
(DQ)
dat|=0x80;
delay(4);}
return(dat);}
//Write a byte functionWriteOneChar
(unsigned char dat)
{unsigned char i=0;
for (i=8; i>0; i--)
{DQ = 0;
DQ = dat&0x01;
delay(5)
; DQ = 1;
dat>>=1;}}
(2) Read temperature and calculate functionReadTemperature
(void)
{unsigned char a=0;
unsigned char b=0;
unsigned int t=0;
float tt=0;
Init_DS18B20();
WriteOneChar(0xCC); // Skip reading serial number and column
numberWriteOneChar(0x44); // Start temperature conversionInit_DS18B20
();
WriteOneChar(0xCC); // Skip reading serial number and column
numberWriteOneChar(0xBE); // Read temperature registers, etc. (9 registers can be read in total) The first two are temperaturea
=ReadOneChar();
b=ReadOneChar();
t=b;
t<<=8;
t=t|a;
tt=t*0.0625;
t= tt*10+0.5; // Amplify the output by 10 times and round it off---this line is useless
(3) See the main program part
abovereturn(t);}

3. Conclusion
AT89C2051 single-chip microcomputer is small in size, light in weight, strong in anti-interference ability, low in environmental requirements, low in price, high in reliability and good in flexibility. Even if you are not a professional in electronic computers, you can rely on your own technical strength to develop the desired single-chip microcomputer application system after learning some basic professional knowledge. The temperature control system in this article is just an example of the widespread application of single-chip microcomputers in various industries. I believe that readers will rely on their own wisdom to make the application of single-chip microcomputers more extensive. In addition, this example can be expanded. The application of single-chip microcomputers is becoming more and more extensive. Due to the poor computing function of single-chip microcomputers, they often need to rely on computer systems. Therefore, remote communication between single-chip microcomputers and PCs is more practical. At present, this design has been successfully applied to the room temperature control of drilling simulator laboratories.

The author of this article has innovative views: the single-chip microcomputer AT89C2051 used has high cost performance, and the method of temperature conversion of temperature sensor DS18B20 is very simple and accurate, and the test range is wide.

References
[1] Lin Shenmao. A thorough study of the basics of 8051 single-chip microcomputers. Beijing: People’s Posts and Telecommunications Press, 2004.
[2] Fan Fengqiang et al. A collection of practical applications of single-chip microcomputer language C51. Beijing: Publishing House of Electronics Industry, 2005.
[3] Tan Haoqiang. C language programming (Second Edition). Beijing: Tsinghua University Press, 1999.
[4] Xia Louis et al. Circuit schematics and circuit board design tutorial. Beijing: Beijing Hope Electronics Press, 2002.
[5] Zhao Jing. Advanced application of Protel99. Beijing: People’s Posts and Telecommunications Press, 2000.
[6] Nie Yi. Analysis and compensation of single-chip microcomputer timer interrupt time error [J]. Microcomputer Information, 2002, 18 (4): 37~38.

Reference address:Temperature Measurement System Based on 51 Single Chip Microcomputer

Previous article:Design of Multiple Schemes for Communication between DSP and 51 Single Chip Microcomputer
Next article:Design of Ultrasonic Distance Measuring Device Based on 51 Single Chip Microcomputer

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号