DS18B20 and ADC0832 are used together

Publisher:哈哈哈33Latest update time:2015-05-19 Source: 51heiKeywords:DS18B20 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
#include
#define  uchar  unsigned char
sbit DQ=P1^4;
volatile data temp_data[2]={0x00,0x00};
uchar 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} ;
//Common cathode digital tube
uchar code table[11] ={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x00}; // 0,1,2,3,4,5, 6,7,8,9, hundreds digit or when the highest digit is 0, it will not be displayed
uchar code table1[10]={0xbf,0x86,0xdb,0xcf,0xe6,0xed,0xfd,0x87,0xff,0xef}; // 0., 1., 2., 3., 4., 5., 6., 7., 8., 9. Each digit has a decimal point

    //The following is the water level display area
#define uchar unsigned char
#define uint unsigned int
#define long unsigned long
#define _rrca_() CY = ACC & 0x01 //Generate RRC A instruction
#define _rlca_() CY = ACC & 0x80 //Generate RLC A instruction
sbit bADcs=P1^7;
sbit bADcl=P1^6;
sbit bADda=P1^5;
sbit flag=P1^3;
//sbit str=P2^7;
//sbit d=P2^6;
//sbit clk=P2^5;
bit choose=0;
unsigned char data1;
unsigned char count;
unsigned char cycle;
uint ge,xiao1,xiao2;
unsigned long data2;
unsigned char  code tablewe[]=
{
 0xFE,0xFD,0xFB,0xF7,
 0xEF,0xDF,0xBF,0x7F
};//Written by myself
void delay_18b20(unsigned int i)
{
while(i--);
}
//Function area water level
void Delay(fly i)
 {
  while(--i);
 }
void ad(void)
{ fly i;
     //data1=0;
     bADcs = 0; //When ADC0832 is not working, its CS input should be high level, and the chip is disabled.
  bADcl=0;
  sea=1;
  bADcl=1;
  bADcl=0;//i down
  sea=1;
  bADcl=1;
  bADcl=0; //   2 down
  sea=0;
  bADcl=1;
  bADcl=0; //   3 down
  sea=1;
  bADcl=1;
  bADcl=0; //   4 down

  for(i=8;i>0;i--)
   {
  
   data1<<=1;
   bADcl=0;
  bADcl=1;
  if(bADda==1) data1|=0x01;
      sea=1;
   }
   bADcs=1;
 
}
void cal()
{
data2=((head)data1*493)/252.5;
ge=data2/100;
xiao1=(data2%100)/10;
xiao2=data2%10;

}

display2()
{
      P2=tablewe[4]; //P2 port low four bits selection
      P0=0x00; //P0 port digital tube segment selects the fifth digital tube and does not use it
   delay_18b20(50);

           P2=tablewe[5];
      P0=table1[ge];
   delay_18b20(50);
           P2=tablewe[6];
      P0=table[xiao1];
      delay_18b20(50);
           P2=tablewe[7];
     P0=table[xiao2];

 

}

//The above is the water level function

 


// Initialization function
Init_DS18B20(void)
{
unsigned char x=0;
DQ=1; //DQ reset
delay_18b20(8); //delay a little
DQ=0; //MCU pulls DQ low
delay_18b20(80); //Precise delay greater than 480us
DQ=1; //Pull the bus high
delay_18b20(14);
x=DQ; //After a short delay, if x=0, initialization is successful, if x=1, initialization fails
delay_18b20(20);
}

 


ReadOneChar(void)
{
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_18b20(4) ;
    }

      return (that) ;
}

 [page]

WriteOneChar(unsigned char dat)
{
    unsigned char i=0;
    for(i=8;i>0;i--)
    {
      DQ=0;
      DQ=dat&0x01;
      delay_18b20(5);

      DQ=1;
      that>>=1;
    }
}

 

Read_Temperature(void)
{
       Heat_DS18B20() ;
 
       WriteOneChar(0xCC); // Skip the operation of reading the serial number and column number
       WriteOneChar(0x44); // Start temperature conversion

       Heat_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[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]==0) //high bit is 0, not displayed
     {
       display[3]=10 ;            
       if(display[2]==0) //The second highest bit is 0, not displayed
       display[2]=10 ;
     }
}

display1()
{

      P2=tablewe[0]; //P2 port low four bits selection
      P0=table[display[3]]; //P0 port digital tube segment selection
   delay_18b20(50);

           P2=tablewe[1];
      P0=table[display[2]];
   delay_18b20(50);
           P2=tablewe[2];
      P0=table1[display[1]];
      delay_18b20(50);
           P2=tablewe[3];
     P0=table[display[0]];

}

void main()
{
   while(1)
    { Read_Temperature();
   Disp_Temperature();
 display1();
       ad();
          cal();
  display2();
   
    }
}

This program can be used, but it just can't display temperatures below zero. Please modify it!
Keywords:DS18B20 Reference address:DS18B20 and ADC0832 are used together

Previous article:The single chip microcomputer uses a digital tube to display 0-9, Af
Next article:DS1302 program based on C8051F

Recommended ReadingLatest update time:2024-11-15 16:51

Design and implementation of a correlation temperature detection system based on DS18B20
Communication base stations are densely populated with equipment and require high security. However, base stations cannot be manually guarded 24 hours a day. Generally, only air conditioning and ventilation fans are used to ensure normal temperature in the station. Temperature detection is rarely located in each equipm
[Microcontroller]
Design and implementation of a correlation temperature detection system based on DS18B20
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)
Research on CRC Algorithm
In the past two days, I studied the CRC algorithm at home because I needed to verify the data read by DS18B20 with AVR. I learned some methods on the Internet and finally figured it out. I wrote it into a C++ class library and hope it will be helpful to everyone. After testing, it was successful! Directly call CRC::
[Microcontroller]
Single-chip data communication: 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. Each
[Microcontroller]
Single-chip data communication: single bus data transmission
PIC MCU DS18B20 Temperature Alarm Program and Simulation
1. Use direct-insertion digital temperature sensor DS18B20;  2. This program only displays the positive part, please solve the negative part by yourself, and the accuracy is reserved to the last two digits;  3. Using the skip ROM instruction of DS18B20 does not support the acquisition of multiple sensors on a sing
[Microcontroller]
PIC MCU DS18B20 Temperature Alarm Program and Simulation
AVR microcontroller reads DS18B20 temperature and uploads it to the serial port program
#include avr/io.h          #include util/delay.h #include avr/interrupt.h //Interrupt function header file //×××××××××××××pin macro definition×××××××××××××× //18B20 definition #define SET_DQ (PORTE) |= (1 (PE7)) // 18b20 high level #define CLR_DQ (PORTE) &=~(1 (PE7)) // 18b20 low level #define DQ_IN (PINE) & (1 (PE
[Microcontroller]
adc0832 and at89s52 interface circuit and vacuum data collection
Vacuum systems are widely used in industries such as electric power, petrochemicals, medical pharmaceuticals, plastics, environmental protection, and medical equipment. With the continuous expansion and deepening of vacuum application fields, the requirements for vacuum technical indicators are becoming higher and hig
[Microcontroller]
adc0832 and at89s52 interface circuit and vacuum data collection
C language program using DS18B20 temperature sensor in single chip microcomputer (reference 2)
/*--------------------------------------------------------------------------------------------------- Function: Read DS18B20 Principle: Single bus protocol Note: The single bus protocol has strict requirements on delay. This program uses a 11.0592M crystal oscillator. If you use other crystal oscillators, please m
[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号