⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ds18b20.lst

📁 一个集合DS18B20的多路温度测量系统,加上adc0809数据采集,加上1602液晶显示的综合数据处理系统,有较高学习价值.
💻 LST
字号:
C51 COMPILER V7.10   DS18B20                                                               01/12/2007 15:01:16 PAGE 1   


C51 COMPILER V7.10, COMPILATION OF MODULE DS18B20
OBJECT MODULE PLACED IN DS18B20.OBJ
COMPILER INVOKED BY: d:\Keil\C51\BIN\C51.EXE DS18B20.c BROWSE DEBUG OBJECTEXTEND

line level    source

   1          #include "system.h"
   2          #include "intrins.h"
   3          
   4          sbit DQ = P3^7;                                            //温度输入口
   5          
   6          unsigned int h;
   7          
   8          
   9          unsigned char ditab[16] = {0x00,0x01,0x01,0x02,0x03,0x03,0x04,0x04,0x05,0x06,0x06,0x07,0x08,0x08,0x09,0x09
             -};
  10          
  11          
  12          /****************************延时函数*******************************/
  13          void delay(unsigned int t)
  14          {
  15   1              for(;t > 0; t--);
  16   1      }
  17          
  18          /****************************DS18B20复位函数*******************************/
  19          ow_reset(void)
  20          {
  21   1              char presence = 1;
  22   1              while (presence)
  23   1              {
  24   2                      while (presence)
  25   2                      {
  26   3                              DQ = 1;
  27   3      
  28   3                              _nop_();
  29   3                              _nop_();
  30   3      
  31   3                              DQ = 0;
  32   3                              delay(50);
  33   3      
  34   3                              DQ = 1;
  35   3                              delay(6);
  36   3      
  37   3                              presence = DQ;
  38   3                      }
  39   2                      delay (45);
  40   2                      presence = ~DQ;
  41   2              }
  42   1              DQ  = 1;
  43   1      }
  44          
  45          
  46          
  47          
  48          /****************************DS18B20写命令函数*******************************/
  49          //向1-wire    总线上写一个字节
  50          void write_byte(unsigned char val)
  51          {
  52   1              unsigned char i;
  53   1              for(i = 8; i > 0; i--)
  54   1              {
C51 COMPILER V7.10   DS18B20                                                               01/12/2007 15:01:16 PAGE 2   

  55   2                      DQ = 1;
  56   2                      _nop_();
  57   2                      _nop_();
  58   2                      
  59   2                      DQ = 0;                                                                                          //延时5us
  60   2                      _nop_();
  61   2                      _nop_();
  62   2                      _nop_();
  63   2                      _nop_();
  64   2                      _nop_();
  65   2                      
  66   2                      DQ = val & 0x01;                                                                        //最低位益出
  67   2                      delay(6);                                                                                       //66us
  68   2                      val = val / 2;                                                                          //右移一位
  69   2              }
  70   1              DQ = 1;
  71   1              delay(1);
  72   1      }
  73          
  74          
  75          /****************************DS18B20读字节函数*******************************/
  76          unsigned char read_byte(void)
  77          {
  78   1              unsigned char i;
  79   1              unsigned char value = 0;
  80   1              
  81   1              for(i = 8; i > 0; i--)
  82   1              {
  83   2                      DQ = 1;;
  84   2                      _nop_();
  85   2                      _nop_();
  86   2      
  87   2                      value >>= 1;
  88   2                      DQ = 0;                                           //4us
  89   2                      _nop_();
  90   2                      _nop_();
  91   2                      _nop_();
  92   2                      _nop_();
  93   2                      
  94   2                      DQ = 1;                                          //4us
  95   2                      _nop_();
  96   2                      _nop_();
  97   2                      _nop_();
  98   2                      _nop_();
  99   2                      
 100   2                      if(DQ)
 101   2                      value |= 0x80;
 102   2                      delay(6);                                        //66us
 103   2              }
 104   1              DQ = 1;
 105   1              return (value);
 106   1      }
 107          
 108          
 109          /***************************读出温度函数******************************/
 110          void read_temp()
 111          {
 112   1              ow_reset();                                                                               //总线复位
 113   1              write_byte(0xCC);                                                                 //发SKIP ROM命令
 114   1              write_byte(0xBE);                                                                 //发读命令
 115   1              temp_data[0] = read_byte();                                               //温度低8位
*** ERROR C202 IN LINE 115 OF DS18B20.C: 'temp_data': undefined identifier
C51 COMPILER V7.10   DS18B20                                                               01/12/2007 15:01:16 PAGE 3   

 116   1              temp_data[1] = read_byte();                                               //温度高8位
*** ERROR C202 IN LINE 116 OF DS18B20.C: 'temp_data': undefined identifier
 117   1              ow_reset();                                                                               
 118   1              write_byte(0xCC);                                                                 
 119   1              write_byte(0x44);                                                                 //SKIP ROM
 120   1      }                                                                                                         //发转换命令
 121          
 122          
 123          
 124          
 125          /***************************温度数据处理函数******************************/
 126          void work_temp()
 127          {
 128   1              unsigned char n = 0;
 129   1              if(temp_data[1] > 127)
*** ERROR C202 IN LINE 129 OF DS18B20.C: 'temp_data': undefined identifier
 130   1              {
 131   2                      temp_data[1] = (256-temp_data[1]);                              //负温度求补码
*** ERROR C202 IN LINE 131 OF DS18B20.C: 'temp_data': undefined identifier
 132   2                      temp_data[0] = (256-temp_data[0]);
*** ERROR C202 IN LINE 132 OF DS18B20.C: 'temp_data': undefined identifier
 133   2                      n = 1;
 134   2              }
 135   1      
 136   1              display[4] = temp_data[0] & 0x0f;
*** ERROR C202 IN LINE 136 OF DS18B20.C: 'display': undefined identifier
 137   1              display[0] = ditab[display[4]];
*** ERROR C202 IN LINE 137 OF DS18B20.C: 'display': undefined identifier
 138   1              //display[3] = temp_data[0] & 0x0f;
 139   1              //display[0] = ditab[display[3]];
 140   1      
 141   1              display[4] = ((temp_data[0] & 0xf0 >> 4) | (temp_data[1] & 0x0f) << 4);
*** ERROR C202 IN LINE 141 OF DS18B20.C: 'display': undefined identifier
 142   1              //display[3] = ((temp_data[0] & 0xf0 >> 4) | (temp_data[1] & 0x0f) << 4);
 143   1              display[3] = display[4]/100;
*** ERROR C202 IN LINE 143 OF DS18B20.C: 'display': undefined identifier
 144   1              display[1] = display[4]%100;
*** ERROR C202 IN LINE 144 OF DS18B20.C: 'display': undefined identifier
 145   1              display[2] = display[1]/10;
*** ERROR C202 IN LINE 145 OF DS18B20.C: 'display': undefined identifier
 146   1              display[1] = display[1]%10;
*** ERROR C202 IN LINE 146 OF DS18B20.C: 'display': undefined identifier
 147   1      
 148   1              if(!display[3])                                                          //最高位为0时都不显示
*** ERROR C202 IN LINE 148 OF DS18B20.C: 'display': undefined identifier
 149   1              {
 150   2                      display[3] = 0x0A;
*** ERROR C202 IN LINE 150 OF DS18B20.C: 'display': undefined identifier
 151   2      
 152   2                      if(! display[2])
*** ERROR C202 IN LINE 152 OF DS18B20.C: 'display': undefined identifier
 153   2                      {
 154   3                              display[2] = 0x0A;
*** ERROR C202 IN LINE 154 OF DS18B20.C: 'display': undefined identifier
 155   3                  }
 156   2              }
 157   1      
 158   1              if(n)
 159   1              {
 160   2                      display[3] = 0x0B;                            //负温度时最高位显示“-”
*** ERROR C202 IN LINE 160 OF DS18B20.C: 'display': undefined identifier
 161   2              }
C51 COMPILER V7.10   DS18B20                                                               01/12/2007 15:01:16 PAGE 4   

 162   1      }

C51 COMPILATION COMPLETE.  0 WARNING(S),  17 ERROR(S)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -