The LCD1602display.h header file used in the program can be obtained from my other article: http://www.51hei.com/mcu/3292.html is the same file
#include
#include
#include "LCD1602display.h"
sbit DQ=P2^0; //ds18b20
uint wendu=0;
uchar num,num1;
uint temperature=0;
uchar code range[]="===TEMPERTURE===";
uchar code ASCII[]="0123456789.";
uchar code table0[]="ROME TEMP:00.0C ";
uchar code table1[]=" ERRO !!! ";
uchar temp[3]={0,0,0};
//********************Delay
void delay1ms(uint z)
{
uint x,y;
for(x=z;x>0;x--)
for(y=114;y>0;y--);
}
//*************************Initialize
bit init_DS18B20()
{
bit flag; //Store the flag of whether DS18B20 exists, flag=0 means it exists; flag=1 means it does not existDQ
=1;
_nop_(); //Pull up
DQ=0 first;
for(num=0;num<200;num++); //Require to maintain 480~960us
DQ=1; //Release data linefor
(num=0;num<10;num++); //Wait for DS18B20 to respondflag
=DQ; //Responsefor
(num=0;num<200;num++); //Delay long enough (this delay function is to prevent entering a dead end due to lack of signal)
DQ=1; //Release data linereturn
(flag); //Return detection success flag
}
//*******************************Write temperature
datavoid DS18B20_WR_CHAR(uchar byte) // Write low bit first
{
for(num1=0;num1<8;num1++)
{
DQ=1;
_nop_();
DQ=0; // Start writing sequence when the data line is pulled down from high to
lowfor(num=0;num<5;num++);//Wait for 15us
DQ=byte&0x01;
for(num=0;num<15;num++); // Delay about 45us, DS18B20 samples from the data line during about 15~45usbyte
>>=1;
for(num=0;num<1;num++);// Delay 3us, at least 1us recovery period is required between two write sequences
}
DQ=1;//Release data line
}
//**********************************Read temperature data
uchar DS18B20_RD_CHAR() // Read low bit first
{
uchar byte=0;
for(num1=0;num1<8;num1++)
{
DQ=1;
_nop_();
DQ=0; //Give a low pulse
_nop_();
DQ=1;
for(num=0;num<5;num++); //Delay about 15us, so that the host can sample within 15us
byte>>=1;
if(DQ==1)
byte|=0x80;
else
byte|=0x00;
for(num=0;num<1;num++);//Delay 3us, there must be a recovery period greater than 1us between the two read timings
} return ( byte )
;
}
//**** ...temperatureh=0; if(init_DS18B20()==0) { DS18B20_WR_CHAR(0xcc); DS18B20_WR_CHAR(0x44); delay1ms(1000); if(init_DS18B20()==0) { DS18B20_WR_CHAR(0xcc); DS18B20_WR_CHAR(0xBE); _nop_ (); temperaturel=DS18B20_RD_CHAR(); temperatureh=DS18B20_RD_CHAR();
temperature=(temperatureh*256+temperaturel)*0.625;
init_DS18B20();
}
//return (temperature);
}
}
//********************** ********Temperature display
void display_DS18B20()
{
temp[2]=temperature/100%10;
temp[1]=temperature%100/10;
temp[0]=temperature%10;
DisplayListChar(0, 1, table0);
DisplayOneChar(10, 1, ASCII[ temp[2] ] );
DisplayOneChar(11, 1, ASCII[ temp[1] ] );
DisplayOneChar(12, 1, ASCII[10] );
DisplayOneChar(13 , 1, ASCII[ temp[0] ] );
}
//************************************Main function
main( )
{
InitLCM();
DisplayListChar(0,0,range);
DisplayListChar(0,1,table0);
while(1)
{
if( init_DS18B20()==0)
{
DS18B20_WENDU();
display_DS18B20();
}
}
}
Keywords:DSB1820 lcd1602
Reference address:Temperature measurement DSB1820 lcd1602 liquid crystal display
#include
#include
#include "LCD1602display.h"
sbit DQ=P2^0; //ds18b20
uint wendu=0;
uchar num,num1;
uint temperature=0;
uchar code range[]="===TEMPERTURE===";
uchar code ASCII[]="0123456789.";
uchar code table0[]="ROME TEMP:00.0C ";
uchar code table1[]=" ERRO !!! ";
uchar temp[3]={0,0,0};
//********************Delay
void delay1ms(uint z)
{
uint x,y;
for(x=z;x>0;x--)
for(y=114;y>0;y--);
}
//*************************Initialize
bit init_DS18B20()
{
bit flag; //Store the flag of whether DS18B20 exists, flag=0 means it exists; flag=1 means it does not existDQ
=1;
_nop_(); //Pull up
DQ=0 first;
for(num=0;num<200;num++); //Require to maintain 480~960us
DQ=1; //Release data linefor
(num=0;num<10;num++); //Wait for DS18B20 to respondflag
=DQ; //Responsefor
(num=0;num<200;num++); //Delay long enough (this delay function is to prevent entering a dead end due to lack of signal)
DQ=1; //Release data linereturn
(flag); //Return detection success flag
}
//*******************************Write temperature
datavoid DS18B20_WR_CHAR(uchar byte) // Write low bit first
{
for(num1=0;num1<8;num1++)
{
DQ=1;
_nop_();
DQ=0; // Start writing sequence when the data line is pulled down from high to
lowfor(num=0;num<5;num++);//Wait for 15us
DQ=byte&0x01;
for(num=0;num<15;num++); // Delay about 45us, DS18B20 samples from the data line during about 15~45usbyte
>>=1;
for(num=0;num<1;num++);// Delay 3us, at least 1us recovery period is required between two write sequences
}
DQ=1;//Release data line
}
//**********************************Read temperature data
uchar DS18B20_RD_CHAR() // Read low bit first
{
uchar byte=0;
for(num1=0;num1<8;num1++)
{
DQ=1;
_nop_();
DQ=0; //Give a low pulse
_nop_();
DQ=1;
for(num=0;num<5;num++); //Delay about 15us, so that the host can sample within 15us
byte>>=1;
if(DQ==1)
byte|=0x80;
else
byte|=0x00;
for(num=0;num<1;num++);//Delay 3us, there must be a recovery period greater than 1us between the two read timings
} return ( byte )
;
}
//**** ...temperatureh=0; if(init_DS18B20()==0) { DS18B20_WR_CHAR(0xcc); DS18B20_WR_CHAR(0x44); delay1ms(1000); if(init_DS18B20()==0) { DS18B20_WR_CHAR(0xcc); DS18B20_WR_CHAR(0xBE); _nop_ (); temperaturel=DS18B20_RD_CHAR(); temperatureh=DS18B20_RD_CHAR();
temperature=(temperatureh*256+temperaturel)*0.625;
init_DS18B20();
}
//return (temperature);
}
}
//********************** ********Temperature display
void display_DS18B20()
{
temp[2]=temperature/100%10;
temp[1]=temperature%100/10;
temp[0]=temperature%10;
DisplayListChar(0, 1, table0);
DisplayOneChar(10, 1, ASCII[ temp[2] ] );
DisplayOneChar(11, 1, ASCII[ temp[1] ] );
DisplayOneChar(12, 1, ASCII[10] );
DisplayOneChar(13 , 1, ASCII[ temp[0] ] );
}
//************************************Main function
main( )
{
InitLCM();
DisplayListChar(0,0,range);
DisplayListChar(0,1,table0);
while(1)
{
if( init_DS18B20()==0)
{
DS18B20_WENDU();
display_DS18B20();
}
}
}
Previous article:C51 MCU serial communication
Next article:Design of digital voice thermometer
- Popular Resources
- Popular amplifiers
Recommended Content
Latest Microcontroller Articles
He Limin Column
Microcontroller and Embedded Systems Bible
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
MoreSelected Circuit Diagrams
MorePopular Articles
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
MoreDaily News
- 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
- Sandia Labs develops battery failure early warning technology to detect battery failures faster
- Ranking of installed capacity of smart driving suppliers from January to September 2024: Rise of independent manufacturers and strong growth of LiDAR market
- Industry first! Xiaopeng announces P7 car chip crowdfunding is completed: upgraded to Snapdragon 8295, fluency doubled
- P22-009_Butterfly E3106 Cord Board Solution
Guess you like
- Review summary: RTT & Renesas ultra-low power MCU RA2L1 development board
- Phantom Power in Audio Equipment
- View Circuit-CSA and System
- Delayed season planning and preparation progress
- Free Download | 2018 ADI Solution Selection Compilation
- Today's live broadcast: Rochester Electronics Semiconductor Full Lifecycle Solutions Help You Meet the Challenges of Supply Chain Disruptions and Component Discontinuations
- Sharing a carefully adjusted hysteresis comparator
- The simulation result of LC parallel resonance frequency is inconsistent with the calculation. Is it because the component model is not selected correctly?
- Using Bluetooth module for fast IoT circuit design
- Using the Ginkgo USB-I2C adapter and the BMP180/BMP085 sensor to implement an atmospheric pressure detector