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

📄 fat.lst

📁 基于C51及SL811读写U盘的源程序
💻 LST
字号:
C51 COMPILER V7.07   FAT                                                                   07/13/2007 21:38:22 PAGE 1   


C51 COMPILER V7.07, COMPILATION OF MODULE FAT
OBJECT MODULE PLACED IN D:\HEX\Fat.obj
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE Fat.c BROWSE DEBUG OBJECTEXTEND OBJECT(D:\HEX\Fat.obj)

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          //根据文件开始簇号计算文件的逻辑扇区号
  15          //计算公式: 开始逻辑扇区号=(蔟号-2)*每簇扇区数+数据区开始逻辑扇区号
  16          unsigned long FirstSectorofCluster(unsigned int clusterNum)
  17          {
  18   1              unsigned long temp;
  19   1              temp=clusterNum-2;
  20   1              temp=temp*DeviceInfo.BPB_SecPerClus;   
  21   1              temp=temp+DeviceInfo.FirstDataSector;
  22   1              return temp;
  23   1      }
  24          
  25          unsigned int ThisFatSecNum(unsigned int clusterNum)
  26          {
  27   1         unsigned int temp;
  28   1         temp=clusterNum*2;
  29   1         temp=temp/DeviceInfo.BPB_BytesPerSec;
  30   1         temp=temp+DeviceInfo.FatStartSector;
  31   1         return temp;
  32   1      }
  33          
  34          unsigned int ThisFatEntOffset(unsigned int clusterNum)
  35          {
  36   1              unsigned int temp1,temp2;
  37   1              temp1=2*clusterNum;
  38   1              temp2=temp1/DeviceInfo.BPB_BytesPerSec;
  39   1              temp1=temp1-temp2*DeviceInfo.BPB_BytesPerSec;
  40   1              return temp1;
  41   1      }
  42          
  43          unsigned int GetNextClusterNum(unsigned int clusterNum)
  44          {
  45   1              unsigned int FatSecNum,FatEntOffset;
  46   1              
  47   1              FatSecNum=ThisFatSecNum(clusterNum);
  48   1              FatEntOffset=ThisFatEntOffset(clusterNum);
  49   1              if(ThisFile.FatSectorPointer!=FatSecNum)
  50   1              {       
  51   2                      
  52   2                      if(!RBC_Read(FatSecNum,1,FATBUF))
  53   2                              return 0xFFFF;
  54   2                      ThisFile.FatSectorPointer=FatSecNum;
  55   2              }
C51 COMPILER V7.07   FAT                                                                   07/13/2007 21:38:22 PAGE 2   

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

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

 180   1      }


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 + -