DS18B20 temperature display demonstration program (6-digit digital tube display)

Publisher:csydtcLatest update time:2016-11-24 Source: eefocusKeywords:DS18B20 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

#include

sbit DQ = P3^3; //define DS18B20 port DQ 

sbit BEEP=P3^7 ;

 

unsigned char presence ;

 

unsigned char code  LEDData[ ]   = {0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,

                                                          0x80,0x90,0xff};

unsigned char data  temp_data[2] = {0x00,0x00};

unsigned char data  display[5] =  {0x00,0x00,0x00,0x00,0x00};

unsigned char code  ditab[16] =   {0x00,0x01,0x01,0x02,0x03,0x03,0x04,0x04,

                                                       0x05,0x06,0x06,0x07,0x08,0x08,0x09,0x09};

void beep();

sbit DIN = P0^7; //decimal point

bit flash=0; //display switch mark

 

/**********************************************************/

void Delay(unsigned int num)//delay function

{

  while( --num );

}

 

/**********************************************************/

 Init_DS18B20(void) // Initialize DS1820

{

 

     DQ = 1; //DQ reset

     Delay(8); //Slight delay

 

     DQ = 0; //MCU pulls DQ low

     Delay(90); //Precise delay greater than 480us

 

     DQ = 1; //Pull the bus high

     Delay(8);

 

     presence = DQ; //If = 0, initialization is successful, = 1, initialization fails

     Delay(100);

     DQ = 1;

    

     return(presence); //Return signal, 0=presence, 1= no presence

}

/**********************************************************/

ReadOneChar(void) //Read one byte

{

unsigned char i = 0;

unsigned char dat = 0;

 

for (i = 8; i > 0; i--)

  {

    DQ = 0; // Give pulse signal

    that >>= 1;

    DQ = 1; // Give pulse signal

 

    if(DQ)

     that |= 0x80;

    Delay(4);

  }

 

    return (that);

}

 

/**********************************************************/

WriteOneChar(unsigned char dat) //write one byte

{

  unsigned char i = 0;

  for (i = 8; i > 0; i--)

  {

    DQ = 0;

    DQ = dat&0x01;

    Delay(5);

 

    DQ = 1;

    that>>=1;

  }

}

 

/*********************************************************/

 

Read_Temperature(void) //Read temperature

{

  Init_DS18B20();

  if(presence==1)       

   { beep(); flash=1;} //DS18B20 is abnormal, buzzer alarm

   else

   {

     flash=0;

     WriteOneChar(0xCC); // Skip reading the serial number and column number

     WriteOneChar(0x44); // Start temperature conversion

 

     Init_DS18B20();

     WriteOneChar(0xCC); //Skip the operation of reading the serial number and column number

     WriteOneChar(0xBE); //Read temperature register

 

     temp_data[0] = ReadOneChar(); //lower 8 bits of temperature

     temp_data[1] = ReadOneChar(); //high 8 bits of temperature

   }

}

/*********************************************************/

Disp_Temperature() //Display temperature

{

  unsigned char  n=0;

 

  display[4]=temp_data[0]&0x0f;

  display[0]=ditab[display[4]]; //Look up the table to get the decimal value

 

  display[4]=((temp_data[0]&0xf0)>>4)|((temp_data[1]&0x0f)<<4);

  display[3]=display[4]/100;

  display[1]=display[4]%100;

  display[2]=display[1]/10;

  display[1]=display[1]%10;

 

  if(!display[3]) //high bit is 0, not displayed

 

  {

    display[3]=0x0a;           

    if(!display[2]) //The second highest bit is 0, not displayed

     display[2]=0x0a;

  }

 

P0 = 0xc6; //Display C

P2 = 0x7f;

Delay(300);

 

P0 = 0x9c; //display ° 

P2 = 0xbf;

Delay(300);

 

P0 =LEDData[display[0]]; //Display decimal places

P2 = 0xdf;

Delay(300);

 

P0 =LEDData[display[1]]; //Display the unit digit

DIN = 0;

P2 = 0xef;

Delay(300);

 

P0 =LEDData[display[2]]; //Display the tens digit

P2 = 0xf7;

Delay(300);

 

P0 =LEDData[display[3]]; //Display the tens digit

P2 = 0xfb;

Delay(300);

 

P2 = 0xff; // Turn off display

}

 

/*********************************************************/

void beep()

  {

    unsigned char i;

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

    {

      Delay(60);

      BEEP=!BEEP;                 //BEEP取反

    }

    BEEP=1; //Turn off the buzzer

  }

 

/*********************************************************/

void main(void)

{

  while(1)

  {

    Read_Temperature();

 if(flash==0)             

 {Disp_Temperature();}

 else P2 = 0xff ; //DS18B20 is abnormal, turn off the display

  }

}


Keywords:DS18B20 Reference address:DS18B20 temperature display demonstration program (6-digit digital tube display)

Previous article:Generation and use of static library in Keil C51
Next article:Make a calculator with a single chip microcomputer

Recommended ReadingLatest update time:2024-11-17 07:41

Design of networked intelligent temperature sensor based on ARM and DS18B20
As an important tool for obtaining information, sensors play a significant role in industrial production, science and technology, etc. However, with the rapid development of microprocessor technology and the development of automation and intelligence of measurement and control systems, traditional sensors have been
[Industrial Control]
51 MCU Temperature Data Wireless Transmission System Made by nRF905 and DS18B20
       I have made a wireless transmission and collection system for temperature data using DS18B20 and two wireless data transmission modules composed of nRF905. It has been debugged and the effect is good. The hardware circuit diagram is as follows: (The connection between AM, CD and P1.3, P1.4 of the microcontr
[Microcontroller]
DS18B20 Driver
/******************************************************************** Program name: DS18B20 demonstration experiment Clock frequency: internal RC 8M Chip: DS18B20    Pin: **PA0 DATA**           **PD0--PD7 connect to digital tube scanning end 1--8**     **PC0--PC7 connect to digital tube scanning end. .A--G** *********
[Microcontroller]
51 single-chip multi-channel temperature measurement alarm system (AT89C51, multiple DS18B20, LCD1602)
1. Introduction This system is mainly composed of AT89C51, multiple DS18B20 temperature modules and LCD1602. The general principle is that multiple DS18B20 collect temperature data in sequence and transmit it to P2.7 of AT89C51. Finally, the current real-time temperature is displayed through LCD1602. The upper and low
[Microcontroller]
51 single-chip multi-channel temperature measurement alarm system (AT89C51, multiple DS18B20, LCD1602)
Add DS18B20 temperature sensor module to LPC213x ARM board
The boss gave me a temporary task, gave me an LPC213x board, and asked me to add a DS18B20 temperature sensor. I used to write upper-level applications. I know nothing about ARM. I had no choice but to do it anyway. After several days of tuning, I finally finished it. Here is a hot screenshot: The hexadecimal data
[Microcontroller]
Add DS18B20 temperature sensor module to LPC213x ARM board
Design of wireless temperature monitoring system based on ATmega16
With the development and progress of society, more and more occasions have increasingly stringent requirements for temperature, and the application of temperature monitoring systems has received increasing attention. In the field of agricultural development, temperature measurement technology is required in many occ
[Microcontroller]
Design of wireless temperature monitoring system based on ATmega16
Design of multi-point temperature measurement system based on single bus temperature sensor
0 Introduction Multi-point temperature measurement systems are widely used in the industrial field and national production. For example, in the chemical industry, it is often necessary to detect and control the temperature of the liquid in the reactor so that it can be stabilized within a certain temperatur
[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号