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

📄 ledtest.lst

📁 The information in this publication is believed to be accurate as of its publication date. Such info
💻 LST
📖 第 1 页 / 共 4 页
字号:
 693             {uchar owireda;
 694   1          owireda=readowdatabit();
 695   1      /*      if (owireda ==0xff)
 696   1                     {
 697   1                                 tx_str("read one bit program error!");
 698   1                               }
 699   1              if (owireda ==0x00)
 700   1                   {
 701   1                          tx_str("read one bit==0x00!");
 702   1                               }
 703   1          if (owireda ==0x01)
 704   1                   {
 705   1                          tx_str("read one bit==0x01!");
 706   1                               }
 707   1      if ((owireda !=0x01)&&(owireda !=0x00)&&(owireda !=0xff))
 708   1               {
 709   1                          tx_str("read one bit program error !=0x01,0x00,0xff!");
 710   1                              }*/
 711   1              return(owireda);
 712   1              }
 713          
 714          
 715          void wdelay(int us)
 716             {
 717   1           int s;
 718   1               for (s=0;s<us;s++);
 719   1               }
 720          //////////////////////////////////////////////////////////////////////////////
 721          // OW_RESET - performs a reset on the one-wire bus and
 722          // returns the presence detect. Reset is 480us, so delay
 723          // value is (480-24)/16 = 28.5 - we use 29. Presence checked
 724          // another 70us later, so delay is (70-24)/16 = 2.875 - we use 3.
 725          //
 726          /*unsigned char ow_reset(void)
 727          {
 728          unsigned char presence;
 729          owData = 0; //pull DQ line low
 730          wdelay(29); // leave it low for 480us
 731          owData = 1; // allow line to return high
 732          wdelay(3); // wait for presence
 733          presence = owData; // get presence signal
 734          wdelay(25); // wait for end of timeslot
 735          return(presence); // presence signal returned
 736          } // 0=presence, 1 = no part*/
 737          
C51 COMPILER V7.06   LEDTEST                                                               11/22/2005 22:07:04 PAGE 13  

 738          //////////////////////////////////////////////////////////////////////////////
 739          // READ_BYTE - reads a byte from the one-wire bus.
 740          //
 741          unsigned char read_byte(void)
 742          {
 743   1      unsigned char i;
 744   1      unsigned char value = 0;
 745   1      for (i=0;i<8;i++)
 746   1      {
 747   2      if(read_bit()) value|=0x01<<i; // reads byte in, one byte at a time and then
 748   2      // shifts it left
 749   2      wdelay(6); // wait for rest of timeslot
 750   2      }
 751   1      return(value);
 752   1      }
 753          
 754          unsigned char First(uchar conditional)
 755          {int flag; 
 756   1       unsigned char g; // Output bit
 757   1       unsigned char x = 0; 
 758   1       unsigned char m = 1; // ROM Bit index
 759   1       unsigned char n = 0; // ROM Byte index
 760   1       unsigned char k = 1; // bit mask
 761   1       unsigned char discrepMarker = 0; // discrepancy marker
 762   1       unsigned char nxt; // return value
 763   1      
 764   1         LastDeviceFlag = FALSE;
 765   1         LastDiscrepancy = 0;
 766   1         
 767   1         nxt = FALSE; // set the next flag to false
 768   1         crc8=0;
 769   1      
 770   1         flag = ow_reset();
 771   1      
 772   1         if(flag||LastDeviceFlag) // no parts -> return false
 773   1            {
 774   2              LastDiscrepancy = 0; // reset the search
 775   2               return FALSE;
 776   2            }
 777   1        if (conditional)
 778   1                { write_byte(0xec);
 779   2                        }
 780   1        else{
 781   2            write_byte(0xF0);
 782   2            }
 783   1                do
 784   1            // for all eight bytes
 785   1              {
 786   2               x = 0;
 787   2                      /* if(read_bit==0xff)
 788   2                           {
 789   2                                 tx_str("read one bit program error!");
 790   2                               }*/
 791   2               if(read_bit()==1)
 792   2                          {
 793   3                           x = 2;
 794   3                  // tx_str(" first bit=1!");
 795   3                  //  tx_lfbs();
 796   3                      }
 797   2               wdelay(6);
 798   2               if(read_bit()==1) 
 799   2                            {x |= 1; // and its complement
C51 COMPILER V7.06   LEDTEST                                                               11/22/2005 22:07:04 PAGE 14  

 800   3                     // tx_str(" next bit=1!");
 801   3                       //tx_lfbs();
 802   3                                 }
 803   2                 if(x ==3) // there are no devices on the 1-wire
 804   2                              {
 805   3                                        tx_str(" not find slave device!");
 806   3                                         tx_lfbs();
 807   3                         break;
 808   3                                      }
 809   2                 else
 810   2                   {
 811   3                     if(x>0) // all devices coupled have 0 or 1
 812   3                           g = x>>1; // bit write value for search
 813   3                     else
 814   3                       {
 815   4      // if this discrepancy is before the last
 816   4      // discrepancy on a previous Next then pick
 817   4      // the same as last time
 818   4                         if(m<LastDiscrepancy)
 819   4                                                 {
 820   5                                  g = ((ROM_NO[n]&k)>0);
 821   5                                                         }
 822   4                         else // if equal to last pick 1
 823   4                                             {
 824   5                                  g = (m==LastDiscrepancy); // if not then pick 0
 825   5                                                 }
 826   4      // if 0 was picked then record
 827   4      // position with mask k
 828   4                         if (g==0) discrepMarker = m;
 829   4                       }
 830   3                       if(g==1) // isolate bit in ROM[n] with mask k
 831   3                            ROM_NO[n] |= k;
 832   3                      else
 833   3                            ROM_NO[n] &= ~k;
 834   3                       write_bit(g); // ROM search write
 835   3                       m++; // increment bit counter m
 836   3                       k = k<<1; // and shift the bit mask k
 837   3                       if(k==0) // if the mask is 0 then go to new ROM
 838   3                            { // byte n and reset mask
 839   4                              crc8=docrc8(ROM_NO[n],crc8); // accumulate the CRC
 840   4                              n++; k++;
 841   4                            }
 842   3                      }
 843   2               }while(n<8); //loop until through all ROM bytes 0-7
 844   1      if(m<65||crc8) // if search was unsuccessful then
 845   1      LastDiscrepancy=0; // reset the last discrepancy to 0
 846   1      else
 847   1          {
 848   2      // search was successful, so set lastDiscrep,
 849   2      // lastOne, nxt
 850   2           LastDiscrepancy = discrepMarker;
 851   2           LastDeviceFlag = (LastDiscrepancy==0);
 852   2           nxt = TRUE; // indicates search is not complete yet, more
 853   2           tx_str("Find Device!");
 854   2                tx_lfbs();
 855   2            // parts remain
 856   2      }
 857   1      return nxt;
 858   1      }
 859          // Perform Match ROM
 860          //
 861          unsigned char Send_MatchRom(void)
C51 COMPILER V7.06   LEDTEST                                                               11/22/2005 22:07:04 PAGE 15  

 862          {
 863   1      unsigned char i;
 864   1      if(ow_reset()) 
 865   1        {
 866   2         tx_str("owire reset failure!");
 867   2         return FALSE;
 868   2         }
 869   1      write_byte(0x55); // match ROM command
 870   1      for(i=0;i<8;i++)
 871   1      {
 872   2       write_byte(ROM_NO[i]); //send ROM code
 873   2      }
 874   1      return TRUE;
 875   1      }
 876          
 877          //--------------------------------------------------------------------------
 878          // Reset crc16 to the value passed in
 879          //
 880          // 'reset' - data to set crc16 to.
 881          //
 882          void setcrc16(ushort reset)
 883          {
 884   1         utilcrc16 = reset;
 885   1         return;
 886   1      }
 887          //--------------------------------------------------------------------------
 888          // Calculate a new CRC16 from the input data short.  Return the current
 889          // CRC16 and also update the global variable CRC16.
 890          //
 891          // 'portnum'  - number 0 to MAX_PORTNUM-1.  This number is provided to
 892          //              indicate the symbolic port number.
 893          // 'data'     - data to perform a CRC16 on
 894          //
 895          // Returns: the current CRC16
 896          //
 897          ushort docrc16(ushort cdata)
 898          {
 899   1         cdata = (cdata ^ (utilcrc16 & 0xff)) & 0xff;
 900   1         utilcrc16 >>= 8;
 901   1      
 902   1         if (oddparity[cdata & 0xf] ^ oddparity[cdata >> 4])
 903   1           utilcrc16 ^= 0xc001;
 904   1      
 905   1         cdata <<= 6;
 906   1         utilcrc16  ^= cdata;
 907   1         cdata <<= 1;
 908   1         utilcrc16   ^= cdata;
 909   1      
 910   1         return utilcrc16;
 911   1      }


MODULE INFORMATION:   STATIC OVERLAYABLE
   CODE SIZE        =   1119    ----
   CONSTANT SIZE    =     58    ----
   XDATA SIZE       =   ----    ----
   PDATA SIZE       =   ----    ----
   DATA SIZE        =     53      29
   IDATA SIZE       =   ----    ----
   BIT SIZE         =      1    ----
END OF MODULE INFORMATION.


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

⌨️ 快捷键说明

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