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.
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);
}
}
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
- 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
- New China Mobile Onenet NB Development Board
- PicoPlanet – Development board with capacitive touch
- Looking for the distributor of Sonix SN8P2501DSG chip
- 【Qinheng CH582】2, Compilation environment + the first LED program
- AD 20.2.5.213
- Use Solve
- [Raspberry Pi 4B Review] + Building a file server
- Based on LNA design
- Processor system architecture classification
- What is the relationship between PCB line width and via pad size?