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

📄 search.lst

📁 一个温度采集系统的单片机程序与WINDOWS 串口通信程序
💻 LST
📖 第 1 页 / 共 2 页
字号:
 175          // FIND DEVICES
 176          void FindDevices(void)
 177          {
 178   1              unsigned char m;
 179   1              unsigned char number;
C51 COMPILER V7.00  SEARCH                                                                 03/15/2005 14:34:07 PAGE 4   

 180   1              number  =0;
 181   1              if(!OWReset()) //Begins when a presence is detected
 182   1              {
 183   2                      if(First()) //Begins when at least one part is found
 184   2                      {
 185   3                      numROMs=0;
 186   3                              do
 187   3                              {
 188   4                              numROMs++;                      
 189   4                              for(m=0;m<8;m++)
 190   4                                      {
 191   5                                      FoundROM[number][m]=ROM[m]; //Identifies ROM
 192   5                                      //number on found device
 193   5                                      }
 194   4                        number++; 
 195   4                        if(number==1)
 196   4                                      {
 197   5                                      send_rom_flg=1;
 198   5                                      EA      =1;
 199   5                                      IE0     =1;               //启动外部中断0,将10个DS18B20 ID转移到外部ROM
 200   5                                      number=0;
 201   5                                      } 
 202   4      
 203   4                              }while (Next()&&(numROMs<70)); //Continues until no additional devices are found
 204   3                      }
 205   2              }
 206   1      }
 207          
 208          
 209          
 210          // The Next function searches for the next device on the 1-wire bus. If
 211          // there are no more devices on the 1-wire then false is returned.
 212          //
 213          unsigned char Next_sub(void)
 214          {
 215   1      unsigned char m = 1; // ROM Bit index
 216   1      unsigned char n = 0; // ROM Byte index
 217   1      unsigned char k = 1; // bit mask
 218   1      unsigned char x = 0;
 219   1      unsigned char discrepMarker = 0; // discrepancy marker
 220   1      unsigned char g; // Output bit
 221   1      unsigned char nxt; // return value
 222   1      bit data flag;
 223   1      
 224   1      nxt = FALSE; // set the next flag to false
 225   1      //dowcrc = 0; // reset the dowcrc
 226   1      flag = OWReset(); // reset the 1-wire
 227   1      
 228   1      if(flag||doneFlag) // no parts -> return false
 229   1      {
 230   2              lastDiscrep = 0; // reset the search
 231   2              return FALSE;
 232   2      }
 233   1      OWWriteByte(0xEC); // send SearchROM command
 234   1      do
 235   1      // for all eight bytes
 236   1        {
 237   2              x = 0;
 238   2              if(OWReadBit()==1) x = 2;
 239   2              delay(6);
 240   2              if(OWReadBit()==1) x |= 1; // and its complement
 241   2              if(x ==3) // there are no devices on the 1-wire
C51 COMPILER V7.00  SEARCH                                                                 03/15/2005 14:34:07 PAGE 5   

 242   2              break;
 243   2              else
 244   2              {
 245   3                      if(x>0) // all devices coupled have 0 or 1
 246   3                      g = x>>1; // bit write value for search
 247   3                      else
 248   3                      {
 249   4                      // if this discrepancy is before the last
 250   4                      // discrepancy on a previous Next then pick
 251   4                      // the same as last time
 252   4                      if(m<lastDiscrep)
 253   4                      g = ((ROM[n]&k)>0);
 254   4                      else // if equal to last pick 1
 255   4                      g = (m==lastDiscrep); // if not then pick 0
 256   4                      // if 0 was picked then record
 257   4                      // position with mask k
 258   4                      if (g==0) discrepMarker = m;
 259   4                      }
 260   3                      if(g==1) // isolate bit in ROM[n] with mask k
 261   3                      ROM[n] |= k;
 262   3                      else
 263   3                      ROM[n] &= ~k;
 264   3                      OWWriteBit(g); // ROM search write
 265   3                      m++; // increment bit counter m
 266   3                      k = k<<1; // and shift the bit mask k
 267   3                      if(k==0) // if the mask is 0 then go to new ROM
 268   3                      { // byte n and reset mask
 269   4      //              OWCrc(ROM[n]); // accumulate the CRC
 270   4                      n++; k++;
 271   4                      }
 272   3              }       
 273   2         }while(n<8); //loop until through all ROM bytes 0-7
 274   1      
 275   1      //      if(m<65||dowcrc) // if search was unsuccessful then
 276   1              if(m<65)
 277   1              lastDiscrep=0; // reset the last discrepancy to 0
 278   1              else
 279   1              {
 280   2              // search was successful, so set lastDiscrep,
 281   2              // lastOne, nxt
 282   2              lastDiscrep = discrepMarker;
 283   2              doneFlag = (lastDiscrep==0);
 284   2              nxt = TRUE; // indicates search is not complete yet, more
 285   2              // parts remain
 286   2              }
 287   1              return nxt;
 288   1      }
 289          
 290          
 291          // FIRST
 292          // The First function resets the current state of a ROM search and calls
 293          // Next to find the first device on the 1-wire bus.
 294          //
 295          unsigned char First_sub(void)
 296          {
 297   1              lastDiscrep = 0; // reset the rom search last discrepancy global
 298   1              doneFlag = FALSE;
 299   1              return Next_sub(); // call Next and return its return value
 300   1      }
 301          
 302          
 303          
C51 COMPILER V7.00  SEARCH                                                                 03/15/2005 14:34:07 PAGE 6   

 304          
 305          
 306          void FindDevices_sub(void)
 307          {
 308   1              unsigned char m;
 309   1              unsigned char number;
 310   1              number  =0;
 311   1              if(!OWReset()) //Begins when a presence is detected
 312   1              {
 313   2                      if(First_sub()) //Begins when at least one part is found
 314   2                      {
 315   3                      numROMs=0;
 316   3                         do
 317   3                         {
 318   4                              numROMs++;
 319   4                              number++;
 320   4                              for(m=0;m<8;m++)
 321   4                                      {
 322   5                                      FoundROM[number][m]=ROM[m]; //Identifies ROM
 323   5                                      //number on found device
 324   5                                      }
 325   4                        if(number==1)
 326   4                              {
 327   5                                      send_rom_flg=1;
 328   5                                      IE0=1;               //启动外部中断0,将10个DS18B20 ID转移到外部ROM
 329   5                                      number=0;
 330   5                              } 
 331   4      
 332   4                        }while (Next_sub()&&(numROMs<70)); //Continues until no additional devices are found
 333   3                      }
 334   2              }
 335   1      }
 336          
 337          
 338          
 339          


MODULE INFORMATION:   STATIC OVERLAYABLE
   CODE SIZE        =    635    ----
   CONSTANT SIZE    =   ----    ----
   XDATA SIZE       =   ----    ----
   PDATA SIZE       =   ----    ----
   DATA SIZE        =     19      16
   IDATA SIZE       =   ----    ----
   BIT SIZE         =   ----       2
END OF MODULE INFORMATION.


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

⌨️ 快捷键说明

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