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

📄 fat32.lst

📁 利用51单片机对u盘进行读写操作
💻 LST
字号:
C51 COMPILER V7.06   FAT32                                                                 08/10/2005 23:36:36 PAGE 1   


C51 COMPILER V7.06, COMPILATION OF MODULE FAT32
OBJECT MODULE PLACED IN Fat32.OBJ
COMPILER INVOKED BY: D:\Keil51\C51\BIN\C51.EXE Fat32.c BROWSE DEBUG OBJECTEXTEND

stmt level    source

   1          #include "common.h"
   2          #include "Fat.h"
   3          #include "Fat32.h"
   4          #include "SL811.H"
   5          #include "TPBULK.H"
   6          #include "HAL.H"
   7          ////////////////////////////////////////
   8          extern SYS_INFO_BLOCK xdata DeviceInfo;
   9          extern FILE_INFO xdata ThisFile;
  10          extern unsigned char xdata DBUF[BUFFER_LENGTH];
  11          extern unsigned char xdata FATBUF[512];
  12          ////////////////////////////////////////
  13          
  14          unsigned long FirstSectorofCluster32(unsigned long clusterNum)
  15          {
  16   1              unsigned long temp;
  17   1              temp=clusterNum-2;
  18   1              temp=temp*DeviceInfo.BPB_SecPerClus;
  19   1              temp=temp+DeviceInfo.FirstDataSector;
  20   1              return temp;
  21   1      }
  22          
  23          unsigned long ThisFatSecNum32(unsigned long clusterNum)
  24          {
  25   1         unsigned long temp;
  26   1         temp=clusterNum*4;
  27   1         temp=temp/DeviceInfo.BPB_BytesPerSec;
  28   1         temp=temp+DeviceInfo.FatStartSector;
  29   1         return temp;
  30   1      }
  31          
  32          unsigned long ThisFatEntOffset32(unsigned long clusterNum)
  33          {
  34   1              unsigned long temp1,temp2;
  35   1              temp1=4*clusterNum;
  36   1              temp2=temp1/DeviceInfo.BPB_BytesPerSec;
  37   1              temp1=temp1-temp2*DeviceInfo.BPB_BytesPerSec;
  38   1              return temp1;
  39   1      }
  40          
  41          unsigned long GetNextClusterNum32(unsigned long clusterNum)
  42          {
  43   1              unsigned long FatSecNum,FatEntOffset;
  44   1              
  45   1              FatSecNum=ThisFatSecNum32(clusterNum);
  46   1              FatEntOffset=ThisFatEntOffset32(clusterNum);
  47   1              if(ThisFile.FatSectorPointer!=FatSecNum)
  48   1              {       
  49   2                      
  50   2                      if(!RBC_Read(FatSecNum,1,FATBUF))
  51   2                              return 0xFFFFFFFF;
  52   2                      ThisFile.FatSectorPointer=FatSecNum;
  53   2              }
  54   1              
  55   1              ///////////////////////////////////////////////////
C51 COMPILER V7.06   FAT32                                                                 08/10/2005 23:36:36 PAGE 2   

  56   1              clusterNum=LSwapINT32(FATBUF[FatEntOffset],FATBUF[FatEntOffset+1],FATBUF[FatEntOffset+2],FATBUF[FatEntOff
             -set+3]);
  57   1              return clusterNum;
  58   1      }
  59          
  60          unsigned char GoToPointer32(unsigned long pointer)
  61          {
  62   1              
  63   1              unsigned int clusterSize;
  64   1              
  65   1              clusterSize=DeviceInfo.BPB_SecPerClus*DeviceInfo.BPB_BytesPerSec;
  66   1              ThisFile.ClusterPointer=ThisFile.StartCluster;
  67   1              while(pointer>clusterSize)
  68   1              {
  69   2                      pointer-=clusterSize;   
  70   2                      ThisFile.ClusterPointer=GetNextClusterNum32(ThisFile.ClusterPointer);
  71   2                      if(ThisFile.ClusterPointer==0xffffffff)
  72   2                      {
  73   3                      return FALSE;
  74   3                      }
  75   2              }
  76   1              ThisFile.SectorofCluster=pointer/DeviceInfo.BPB_BytesPerSec;
  77   1              ThisFile.SectorPointer=FirstSectorofCluster32(ThisFile.ClusterPointer)+ThisFile.SectorofCluster;
  78   1              ThisFile.OffsetofSector=pointer-ThisFile.SectorofCluster*DeviceInfo.BPB_BytesPerSec;
  79   1              ThisFile.FatSectorPointer=0;
  80   1              return TRUE;
  81   1              
  82   1      }
  83          
  84          unsigned char DeleteClusterLink32(unsigned long clusterNum)
  85          {
  86   1              unsigned long FatSecNum,FatEntOffset;
  87   1              unsigned char i;
  88   1              while((clusterNum>1)&&(clusterNum<DeviceInfo.TotCluster))
  89   1              {
  90   2              FatSecNum=ThisFatSecNum32(clusterNum);
  91   2              FatEntOffset=ThisFatEntOffset32(clusterNum);
  92   2              if(RBC_Read(FatSecNum,1,DBUF))
  93   2                      clusterNum=LSwapINT32(DBUF[FatEntOffset],DBUF[FatEntOffset+1],DBUF[FatEntOffset+2],DBUF[FatEntOffset+3])
             -;
  94   2              else
  95   2                      return FALSE;
  96   2              DBUF[FatEntOffset]=0x00;DBUF[FatEntOffset+1]=0x00;DBUF[FatEntOffset+2]=0x00;DBUF[FatEntOffset+3]=0x00;                  
  97   2              for(i=0;i<DeviceInfo.BPB_NumFATs;i++)
  98   2                      {
  99   3                      DelayMs(5);
 100   3                      if(!RBC_Write(FatSecNum+i*DeviceInfo.BPB_FATSz32,1,DBUF))
 101   3                              return FALSE;
 102   3                      }       
 103   2              }
 104   1              return TRUE;
 105   1      }
 106          
 107          unsigned long GetFreeCusterNum32(void)
 108          {
 109   1              unsigned long xdata clusterNum,i;
 110   1              unsigned long xdata sectorNum;
 111   1              unsigned char xdata j;
 112   1              clusterNum=0;
 113   1              sectorNum=DeviceInfo.FatStartSector;
 114   1              while(sectorNum<DeviceInfo.BPB_FATSz32+DeviceInfo.FatStartSector)
 115   1              {               
C51 COMPILER V7.06   FAT32                                                                 08/10/2005 23:36:36 PAGE 3   

 116   2                      if(!RBC_Read(sectorNum,1,DBUF))
 117   2                              return 0x0;
 118   2                      for(i=0;i<DeviceInfo.BPB_BytesPerSec;i=i+4)
 119   2                              {
 120   3                               if((DBUF[i]==0)&&(DBUF[i+1]==0)&&(DBUF[i+2]==0)&&(DBUF[i+3]==0))
 121   3                                      {       
 122   4                                      DBUF[i]=0xff;DBUF[i+1]=0xff;DBUF[i+2]=0xff;DBUF[i+3]=0xff;
 123   4                                      for(j=0;j<DeviceInfo.BPB_NumFATs;j++)
 124   4                                              {
 125   5                                              DelayMs(5);
 126   5                                              if(!RBC_Write(sectorNum+j*DeviceInfo.BPB_FATSz32,1,DBUF))
 127   5                                                      return FALSE;
 128   5                                              }       
 129   4                                      return  clusterNum; 
 130   4                                      }
 131   3                               clusterNum++;
 132   3                              }                                       
 133   2                      sectorNum=4*clusterNum/DeviceInfo.BPB_BytesPerSec+DeviceInfo.FatStartSector;    
 134   2                      DelayMs(10);
 135   2              }       
 136   1              return 0x0;
 137   1      }
 138          
 139          unsigned long CreateClusterLink32(unsigned long currentCluster)
 140          {
 141   1              unsigned long xdata newCluster;
 142   1              unsigned long xdata FatSecNum,FatEntOffset;
 143   1              unsigned char xdata i;
 144   1      
 145   1              newCluster=GetFreeCusterNum32();
 146   1                      
 147   1              FatSecNum=ThisFatSecNum32(currentCluster);
 148   1              FatEntOffset=ThisFatEntOffset32(currentCluster);
 149   1              if(RBC_Read(FatSecNum,1,DBUF))
 150   1                      {
 151   2                      DBUF[FatEntOffset]=newCluster;
 152   2                      DBUF[FatEntOffset+1]=newCluster>>8;
 153   2                      DBUF[FatEntOffset+2]=newCluster>>16;
 154   2                      DBUF[FatEntOffset+3]=newCluster>>24;
 155   2                      for(i=0;i<DeviceInfo.BPB_NumFATs;i++)
 156   2                              {
 157   3                              DelayMs(5);
 158   3                              if(!RBC_Write(FatSecNum+i*DeviceInfo.BPB_FATSz32,1,DBUF))
 159   3                                      return FALSE;
 160   3                              }               
 161   2                      }
 162   1              else
 163   1                      return 0x00;
 164   1              
 165   1              return newCluster;
 166   1      }


MODULE INFORMATION:   STATIC OVERLAYABLE
   CODE SIZE        =   2089    ----
   CONSTANT SIZE    =   ----    ----
   XDATA SIZE       =   ----      26
   PDATA SIZE       =   ----    ----
   DATA SIZE        =   ----      63
   IDATA SIZE       =   ----    ----
   BIT SIZE         =   ----    ----
END OF MODULE INFORMATION.

C51 COMPILER V7.06   FAT32                                                                 08/10/2005 23:36:36 PAGE 4   


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

⌨️ 快捷键说明

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