Temperature measurement module made of DS18B20

Publisher:dst2015Latest update time:2017-09-02 Source: elecfansKeywords:DS18B20 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

The temperature measurement module made of DS18B20, this single-chip DS18B20 temperature measurement module that can display positive and negative values ​​is made by Electronic Music House Yuanchuang. The port of the single-chip microcomputer driving the digital tube is set to push-pull working mode, so that the use of the entire display circuit is relatively simple, the digital tube segment driver eliminates the current limiting resistor, and the digital tube brightness display is realized by program control of the on-off time. Only 6 components are used: a DS18B20 digital temperature sensor, a USB port, a STC12C4052 single-chip microcomputer, a 4-bit common anode digital tube, a 10uf chip reset capacitor, and a 10k chip reset resistor. Since the circuit is relatively simple, the PCB diagram is given directly here. The designed temperature measurement range is: -9.9~99.9℃. The following is the production process. The source program is attached at the end of the article. The source program is suitable for the STC1T single-chip microcomputer. The following figure is a photo of the actual work that has been produced.

Temperature measurement module made of DS18B20


Temperature measurement module made of DS18B20


Temperature measurement module made of DS18B20


Temperature measurement module made of DS18B20

In order to facilitate the copying of microcontroller enthusiasts, the source program is attached: Note (the header file of the posted program may change, so be careful to modify it yourself

//Use the internal RC oscillator of the microcontroller

#include

#include

#define uchar unsigned char

#define uint unsigned int

sfr P1M0   = 0x91;

sfr P1M1   = 0x92;

sfr P3M0   = 0xB1;

sfr P3M1   = 0xB2;

#define ENABLE_ISP 0x84 //When the system operating clock is <6MHz, set this value to the IAP_CONTR register

sbit temp=P1^7;

sbit LED0=P3^0; //C

sbit LED1=P1^4; // one decimal place

sbit LED2=P1^3; //units digit

sbit LED3=P1^0; // Tens place

sbit A=P1^1;

sbit B_B=P1^5;

sbit C=P3^2;

sbit D=P3^4;

sbit E=P3^5;

sbit F=P1^2;

sbit G=P3^1;

sbit H=P3^3; //decimal point

uchar temp_low,zf,mz;

int temp_high; 

int final_temp;

void dm(mz);

void delay(uint x) //(x+1)*6微

{

while(x--);

}

void delay_long(uint x)

{

uint i;

while(x--)

{

for(i=0;i<125;i++);

}

}

void init_ds18b20()//initialization

{

temp=1;//reset

delay(6); //slight delay

temp=0;

delay(145); //delay greater than 480us(520us)

temp=1;

delay(14); //This time cannot be too long, otherwise the signal detection time will be exceeded

void read_signal()//Read response pulse

{

while(temp);

while(~temp) // response pulse detected

{

delay(7);

break;

}

}

bit readbit_ds18b20()

{

bit b;

temp=1;

delay(6); //slight delay

temp=0;

delay(2); //Keep low for at least 1us (4us)

temp=1;

delay(4); // Output data is valid after 15us delay (23us)

b=temp;

delay(20); //Read time interval is not less than 60us(71us)

return(b);

}

void writebyte_ds18b20(uchar b) // write 0 and 1 together

{

int i,j;

float btemp;

temp=1;

for(i=0;i<8;i++)

{

j=0;

btemp=b&0x01;

b>>=1;

if(btemp==0)

{

temp=0;

delay(18); //Keep the pull-down above 60us (71us)

temp=1;

}

else

{

temp=0;

j++; //Pull high within 15us

temp=1;

delay(18); //The entire write timing is above 60us (71us)

}

}

}

void temp_convert()

{

init_ds18b20(); //initialization

read_signal(); //Read the response pulse

delay_long(4);

writebyte_ds18b20(0xcc); //Skip the verification serial number command. If there are multiple ds18b20s on a single line, this command cannot be used

writebyte_ds18b20(0x44); //Start temperature conversion command

}

char readbyte_ds18b20()

{

uint i;

fly a,b;

b=0;

for(i=0;i<8;i++)

{

a=readbit_ds18b20();

b=(a<

}

return(b);

}

uint read_ds18b20()

{

int y;

float yy;

init_ds18b20(); //initialization

read_signal(); //Read the response pulse

delay_long(4);

writebyte_ds18b20(0xcc); //Skip verification serial number command

writebyte_ds18b20(0xbbe); //Read the data from internal ROM

temp_low=readbyte_ds18b20(); //When reading data, the low bit is in front and the high bit is in the back

temp_high=readbyte_ds18b20();

y=temp_high;

y<<=8;

y=y|temp_low; //integrate into an int type

yy=y*0.0625; //12-bit precision is 0.0625

y=yy*10+0.5;

return(y);

}

void display(uint x)

{

fly sw,gw,xs;

sw=x/100;

gw=x0/10; //unit digit

xs=x; //decimal

if(zf==1)

{

sw=11;

}

else

{

if(sw==0)

{

   sw=12;

}

}

dm(sw);

LED3=1;

delay(30);

LED3=0;

delay(10);

dm(gw);

LED2=1;

delay(30);

LED2=0;

delay(10);

dm(13);

LED2=1;

delay(10);

LED2=0;

delay(10);

dm(xs);

LED1=1;

delay(30);

LED1=0;

delay(10);

dm(10);

LED0=1;

delay(30);

LED0=0;

delay(10);

}

void dm(mz)

{

switch(mz)

{

case 0:A=0;B_B=0;C=0;D=0;E=0;F=0;G=1;H=1;break;

case 1:A=1;B_B=0;C=0;D=1;E=1;F=1;G=1;H=1;break;

case 2:A=0;B_B=0;C=1;D=0;E=0;F=1;G=0;H=1;break;

case 3:A=0;B_B=0;C=0;D=0;E=1;F=1;G=0;H=1;break;

case 4:A=1;B_B=0;C=0;D=1;E=1;F=0;G=0;H=1;break;

case 5:A=0;B_B=1;C=0;D=0;E=1;F=0;G=0;H=1;break;

case 6:A=0;B_B=1;C=0;D=0;E=0;F=0;G=0;H=1;break;

case 7:A=0;B_B=0;C=0;D=1;E=1;F=1;G=1;H=1;break;

case 8:A=0;B_B=0;C=0;D=0;E=0;F=0;G=0;H=1;break;

case 9:A=0;B_B=0;C=0;D=0;E=1;F=0;G=0;H=1;break;

case 10:A=0;B_B=1;C=1;D=0;E=0;F=0;G=1;H=1;break; //C

case 11:A=1;B_B=1;C=1;D=1;E=1;F=1;G=0;H=1;break; //-

case 12:A=1;B_B=1;C=1;D=1;E=1;F=1;G=1;H=1;break; //not displayed

case 13:A=1;B_B=1;C=1;D=1;E=1;F=1;G=1;H=0;break; //小数点

}

}

void main(void)

{

    P1M0 = 0x00;                

    P1M1 = 0x19;   

    P3M0=0x00;

    P3M1=0x01;

  LED0=0;  //C

LED1=0; // one decimal place

LED2=0; //unit digit

LED3=0; // Tens place

read_ds18b20();

temp_convert();

delay_long(5);

delay_long(2000); //delay(5) means delay 555us

while(1)

{

temp_convert();

delay_long(5);

final_temp=read_ds18b20();

if(final_temp<0)

{

  final_temp=-(final_temp-1);

  zf=1;

}

else zf=0;

display(final_temp);

}

}


Keywords:DS18B20 Reference address:Temperature measurement module made of DS18B20

Previous article:51 single chip intelligent temperature controller C language source program
Next article:AT89C52+ADC0809 composed of 0-5V range voltmeter

Recommended ReadingLatest update time:2024-11-16 23:42

Remote Intelligent Automobile Temperature Control System Based on GSM
  The system uses the GSM remote communication system to control the operation of the air conditioner and other equipment in the car. Users can achieve human-computer interaction through text messages, overcoming the problem of short distance of infrared, wireless and other remote control, and can also monitor the s
[Microcontroller]
Remote Intelligent Automobile Temperature Control System Based on GSM
Use DS18B20 and AT89C51 to design a high-precision multi-channel temperature monitoring system and conduct simulation debugging
introduction In real-time temperature monitoring systems, such as greenhouse temperature monitoring, cold storage temperature measurement, intelligent building temperature control and other systems, multi-channel temperature collection and detection are often required. Quickly and reliably collecting high-precision te
[Microcontroller]
Use DS18B20 and AT89C51 to design a high-precision multi-channel temperature monitoring system and conduct simulation debugging
Design of Home Temperature Measuring Device Based on DS18B20 and AT89C2051
1. Design Overview This design uses the USB port as the power supply port, uses the DS18B20 temperature sensor to collect temperature information, uses the AT89C2051 single-chip microcomputer for control, and uses a four-digit common anode digital tube display to achieve temperature measurement and display (the syst
[Microcontroller]
Design of Home Temperature Measuring Device Based on DS18B20 and AT89C2051
DS18B20 single bus data transmission
  A pure single-chip microcomputer cannot do much, and must be equipped with various peripherals. Therefore, it is essential to understand the data communication between the single-chip microcomputer and the sensor. Common single-chip microcomputer data communication methods include SPI, IIC, RS232, single bus, etc. Ea
[Microcontroller]
DS18B20 single bus data transmission
DS18B20 temperature test program (51 single chip digital tube display) + circuit diagram
The following is the circuit diagram using a 4-digit digital tube display program. There are 2 files in total: /********************************************** ds18b20.h header file ************************************************ ****/ #ifndef _DS18B20_H_ #define _DS18B20_H_ #include reg51.h #define led P1 #d
[Microcontroller]
DS18B20 temperature test program (51 single chip digital tube display) + circuit diagram
DS18B20 matches ROM address single bus multi-point temperature measurement (STC89C52)
DS18B20 single bus multi-point temperature measurement, the program realizes single bus two-point temperature measurement and 1602 display by matching the 64-bit ROM address. This program needs to know the 64-bit ROM address of DS18B20 first. The method of reading the ROM address can refer to the introduction in the pr
[Microcontroller]
Summary of the design and production of electronic temperature alarm based on single chip microcomputer
Production plan: This thermometer uses an intelligent temperature sensor DS18B20 as a detection element. The temperature measurement range of this element is -55~125 degrees, and the highest resolution is 0.0625 degrees, which fully meets the requirement of 0.1 degree resolution in this design! Considering the
[Microcontroller]
Summary of the design and production of electronic temperature alarm based on single chip microcomputer
Design of intelligent thermometer based on single chip microcomputer SPCE061A
O Introduction Commonly used thermometers can be divided into the following types according to their materials and uses: glass mercury thermometers, which are accurate and inexpensive, but must be in direct contact with the human body for more than 3 minutes, and are difficult to read due to their fine scal
[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号