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

📄 fat.lst

📁 能用51读写U盘...创建文件格式...能自由创建文件.删除.读写
💻 LST
字号:
C51 COMPILER V7.06   FAT                                                                   08/10/2005 23:25:27 PAGE 1   


C51 COMPILER V7.06, COMPILATION OF MODULE FAT
OBJECT MODULE PLACED IN Fat.OBJ
COMPILER INVOKED BY: D:\Keil51\C51\BIN\C51.EXE Fat.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          unsigned char xdata FATBUF[512];
  12          ////////////////////////////////////////
  13          
  14          unsigned long FirstSectorofCluster(unsigned int 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 int ThisFatSecNum(unsigned int clusterNum)
  24          {
  25   1         unsigned int temp;
  26   1         temp=clusterNum*2;
  27   1         temp=temp/DeviceInfo.BPB_BytesPerSec;
  28   1         temp=temp+DeviceInfo.FatStartSector;
  29   1         return temp;
  30   1      }
  31          
  32          unsigned int ThisFatEntOffset(unsigned int clusterNum)
  33          {
  34   1              unsigned int temp1,temp2;
  35   1              temp1=2*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 int GetNextClusterNum(unsigned int clusterNum)
  42          {
  43   1              unsigned int FatSecNum,FatEntOffset;
  44   1              
  45   1              FatSecNum=ThisFatSecNum(clusterNum);
  46   1              FatEntOffset=ThisFatEntOffset(clusterNum);
  47   1              if(ThisFile.FatSectorPointer!=FatSecNum)
  48   1              {       
  49   2                      
  50   2                      if(!RBC_Read(FatSecNum,1,FATBUF))
  51   2                              return 0xFFFF;
  52   2                      ThisFile.FatSectorPointer=FatSecNum;
  53   2              }
  54   1              
  55   1              ///////////////////////////////////////////////////
C51 COMPILER V7.06   FAT                                                                   08/10/2005 23:25:27 PAGE 2   

  56   1              clusterNum=FATBUF[FatEntOffset+1];
  57   1              clusterNum=clusterNum<<8;
  58   1              clusterNum+=FATBUF[FatEntOffset];       
  59   1              return clusterNum;
  60   1      }
  61          
  62          unsigned char GoToPointer(unsigned long pointer)
  63          {
  64   1              
  65   1              unsigned int clusterSize;
  66   1              
  67   1              clusterSize=DeviceInfo.BPB_SecPerClus*DeviceInfo.BPB_BytesPerSec;
  68   1              ThisFile.ClusterPointer=ThisFile.StartCluster;
  69   1              while(pointer>clusterSize)
  70   1              {
  71   2                      pointer-=clusterSize;   
  72   2                      ThisFile.ClusterPointer=GetNextClusterNum(ThisFile.ClusterPointer);
  73   2                      if(ThisFile.ClusterPointer==0xffff)
  74   2                      {
  75   3                      return FALSE;
  76   3                      }
  77   2              }
  78   1              ThisFile.SectorofCluster=pointer/DeviceInfo.BPB_BytesPerSec;
  79   1              ThisFile.SectorPointer=FirstSectorofCluster(ThisFile.ClusterPointer)+ThisFile.SectorofCluster;
  80   1              ThisFile.OffsetofSector=pointer-ThisFile.SectorofCluster*DeviceInfo.BPB_BytesPerSec;
  81   1              ThisFile.FatSectorPointer=0;
  82   1              return TRUE;
  83   1              
  84   1      }
  85          
  86          unsigned char DeleteClusterLink(unsigned int clusterNum)
  87          {
  88   1              unsigned int FatSecNum,FatEntOffset;
  89   1              unsigned char i;
  90   1              while((clusterNum>1)&&(clusterNum<0xfff0))
  91   1              {
  92   2              FatSecNum=ThisFatSecNum(clusterNum);
  93   2              FatEntOffset=ThisFatEntOffset(clusterNum);
  94   2              if(RBC_Read(FatSecNum,1,DBUF))
  95   2                      {
  96   3                      clusterNum=DBUF[FatEntOffset+1];
  97   3                      clusterNum=clusterNum<<8;
  98   3                      clusterNum+=DBUF[FatEntOffset]; 
  99   3                      }
 100   2              else
 101   2                      return FALSE;
 102   2              DBUF[FatEntOffset]=0x00;
 103   2              DBUF[FatEntOffset+1]=0x00;      
 104   2              for(i=0;i<DeviceInfo.BPB_NumFATs;i++)
 105   2                      {
 106   3                      DelayMs(5);
 107   3                      if(!RBC_Write(FatSecNum+i*DeviceInfo.BPB_FATSz16,1,DBUF))
 108   3                              return FALSE;
 109   3                      }       
 110   2              }
 111   1              return TRUE;
 112   1      }
 113          
 114          unsigned int GetFreeCusterNum(void)
 115          {
 116   1              unsigned int clusterNum,i;
 117   1              unsigned long sectorNum;
C51 COMPILER V7.06   FAT                                                                   08/10/2005 23:25:27 PAGE 3   

 118   1              unsigned char j;
 119   1              clusterNum=0;
 120   1              sectorNum=DeviceInfo.FatStartSector;
 121   1              while(sectorNum<DeviceInfo.BPB_FATSz16+DeviceInfo.FatStartSector)
 122   1              {
 123   2                      
 124   2                      if(!RBC_Read(sectorNum,1,DBUF))
 125   2                              return 0x0;
 126   2                      for(i=0;i<DeviceInfo.BPB_BytesPerSec;i=i+2)
 127   2                              {
 128   3                               if((DBUF[i]==0)&&(DBUF[i+1]==0))
 129   3                                      {       
 130   4                                      DBUF[i]=0xff;
 131   4                                      DBUF[i+1]=0xff;
 132   4                                      for(j=0;j<DeviceInfo.BPB_NumFATs;j++)
 133   4                                              {
 134   5                                              DelayMs(5);
 135   5                                              if(!RBC_Write(sectorNum+j*DeviceInfo.BPB_FATSz16,1,DBUF))
 136   5                                                      return FALSE;
 137   5                                              }       
 138   4                                      return  clusterNum; 
 139   4                                      }
 140   3                               clusterNum++;
 141   3                              }       
 142   2                                      
 143   2                      sectorNum=2*clusterNum/DeviceInfo.BPB_BytesPerSec+DeviceInfo.FatStartSector;    
 144   2                      DelayMs(10);
 145   2              }
 146   1              
 147   1              return 0x0;
 148   1      }
 149          
 150          unsigned int CreateClusterLink(unsigned int currentCluster)
 151          {
 152   1              unsigned int newCluster;
 153   1              unsigned int FatSecNum,FatEntOffset;
 154   1              unsigned char i;
 155   1      
 156   1              newCluster=GetFreeCusterNum();
 157   1      
 158   1              if(newCluster==0)
 159   1                      return 0x00;
 160   1                              
 161   1              FatSecNum=ThisFatSecNum(currentCluster);
 162   1              FatEntOffset=ThisFatEntOffset(currentCluster);
 163   1              if(RBC_Read(FatSecNum,1,DBUF))
 164   1                      {
 165   2                      DBUF[FatEntOffset]=newCluster;
 166   2                      DBUF[FatEntOffset+1]=newCluster>>8;
 167   2                      for(i=0;i<DeviceInfo.BPB_NumFATs;i++)
 168   2                              {
 169   3                              DelayMs(5);
 170   3                              if(!RBC_Write(FatSecNum+i*DeviceInfo.BPB_FATSz16,1,DBUF))
 171   3                                      return FALSE;
 172   3                              }               
 173   2                      }
 174   1              else
 175   1                      return 0x00;
 176   1              
 177   1              return newCluster;
 178   1      }

C51 COMPILER V7.06   FAT                                                                   08/10/2005 23:25:27 PAGE 4   


MODULE INFORMATION:   STATIC OVERLAYABLE
   CODE SIZE        =   1337    ----
   CONSTANT SIZE    =   ----    ----
   XDATA SIZE       =    512    ----
   PDATA SIZE       =   ----    ----
   DATA SIZE        =   ----      41
   IDATA SIZE       =   ----    ----
   BIT SIZE         =   ----    ----
END OF MODULE INFORMATION.


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

⌨️ 快捷键说明

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