#include
#define uint unsigned int
#define uchar unsigned char
sbit DQ=P2^0;//P2^0
uchar code tab[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};//without decimal point
uchar code tab1[]={0x40,0x79,0x24,0x30,0x19,0x12,0x02,0x78,0x00,0x10};//with decimal point
sbit wei0=P0^0;//P3^2
sbit wei1=P0^1;//P3^3
//sbit wei2=P1^2;
//sbit wei3=P1^3;
uchar disdata[2];
uint tvalue;
uchar tflag;
void delay(uint i)
{
while(i--);
}
void ds1820rst()//Reset
{
DQ=1;
delay(4); DQ =
0;
delay(100); DQ = 1
;
delay(40); }
uchar ds1820rd
()//Read data
{
uchar i; uchar dat=0; for ( i=8; i >0;i-- ) { DQ = 0 ; data 10 ) ; DQ=1; wdata>>=1; } } read_temp()/*read temperature value and convert*/ { uchar a,b; ds1820rst(); ds1820wr(0xcc);//*skip reading serial number*/ ds1820wr(0x44);//*start temperature conversion*/ ds1820rst(); ds1820wr(0xcc);//*skip reading serial number*/ ds1820wr(0xbe);//*read temperature*/ a=ds1820rd(); b=ds1820rd(); tvalue=b; tvalue<<=8; tvalue=tvalue|a; if(tvalue<0x0fff) tflag=0; else {tvalue=~tvalue+1; tflag=1; } tvalue=(tvalue*0.0625);//0.625 temperature value is enlarged 10 times, accurate to 1 decimal placereturn (tvalue); } void ds1820disp()//temperature value display { disdata[0]=tvalue/10;//ten digitsdisdata [1]=tvalue%10;//one digitwei0 =0; P1=tab[disdata[0]]; delay(250); wei0=1; wei1=0; P1=tab[disdata[1]]; delay(250); wei1=1; } void main() { while(1) { read_temp();//read temperatureds1820disp ();//display } }
Keywords:DS18B20
Reference address:DS18B20 and digital tube program
#define uint unsigned int
#define uchar unsigned char
sbit DQ=P2^0;//P2^0
uchar code tab[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};//without decimal point
uchar code tab1[]={0x40,0x79,0x24,0x30,0x19,0x12,0x02,0x78,0x00,0x10};//with decimal point
sbit wei0=P0^0;//P3^2
sbit wei1=P0^1;//P3^3
//sbit wei2=P1^2;
//sbit wei3=P1^3;
uchar disdata[2];
uint tvalue;
uchar tflag;
void delay(uint i)
{
while(i--);
}
void ds1820rst()//Reset
{
DQ=1;
delay(4); DQ =
0;
delay(100); DQ = 1
;
delay(40); }
uchar ds1820rd
()//Read data
{
uchar i; uchar dat=0; for ( i=8; i >0;i-- ) { DQ = 0 ; data 10 ) ; DQ=1; wdata>>=1; } } read_temp()/*read temperature value and convert*/ { uchar a,b; ds1820rst(); ds1820wr(0xcc);//*skip reading serial number*/ ds1820wr(0x44);//*start temperature conversion*/ ds1820rst(); ds1820wr(0xcc);//*skip reading serial number*/ ds1820wr(0xbe);//*read temperature*/ a=ds1820rd(); b=ds1820rd(); tvalue=b; tvalue<<=8; tvalue=tvalue|a; if(tvalue<0x0fff) tflag=0; else {tvalue=~tvalue+1; tflag=1; } tvalue=(tvalue*0.0625);//0.625 temperature value is enlarged 10 times, accurate to 1 decimal placereturn (tvalue); } void ds1820disp()//temperature value display { disdata[0]=tvalue/10;//ten digitsdisdata [1]=tvalue%10;//one digitwei0 =0; P1=tab[disdata[0]]; delay(250); wei0=1; wei1=0; P1=tab[disdata[1]]; delay(250); wei1=1; } void main() { while(1) { read_temp();//read temperatureds1820disp ();//display } }
Previous article:Review PS2 keyboard decoding
Next article:LCD12864 specified position reverse display program
- Popular Resources
- Popular amplifiers
Recommended Content
Latest Microcontroller Articles
- Learn ARM development(16)
- Learn ARM development(17)
- Learn ARM development(18)
- Embedded system debugging simulation tool
- A small question that has been bothering me recently has finally been solved~~
- Learn ARM development (1)
- Learn ARM development (2)
- Learn ARM development (4)
- Learn ARM development (6)
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
- Analysis of the application of several common contact parts in high-voltage connectors of new energy vehicles
- Wiring harness durability test and contact voltage drop test method
- From probes to power supplies, Tektronix is leading the way in comprehensive innovation in power electronics testing
- From probes to power supplies, Tektronix is leading the way in comprehensive innovation in power electronics testing
- Sn-doped CuO nanostructure-based ethanol gas sensor for real-time drunk driving detection in vehicles
- Design considerations for automotive battery wiring harness
- Do you know all the various motors commonly used in automotive electronics?
- What are the functions of the Internet of Vehicles? What are the uses and benefits of the Internet of Vehicles?
- Power Inverter - A critical safety system for electric vehicles
- Analysis of the information security mechanism of AUTOSAR, the automotive embedded software framework
Guess you like
- The difference between various chips in TI's CC series: CC2430 CC1100
- happy holidays
- 【Tuya BK7231N】Unboxing Experience
- PIC32_CANbus cannot receive signal
- New package cannot be saved
- Technical characteristics and wide application of embedded systems
- Student dormitory apartment monitoring system based on Internet of Things
- 【DIY】Make a 5V input car light controller
- Linux self-study notes (II) Linux disk partition
- EEWORLD University Hall ---- Intelligent Information Processing Peking University Tan Ying