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

📄 fat32.lst

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


C51 COMPILER V7.07, COMPILATION OF MODULE FAT32
OBJECT MODULE PLACED IN D:\HEX\Fat32.obj
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE Fat32.c BROWSE DEBUG OBJECTEXTEND OBJECT(D:\HEX\Fat32.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          extern unsigned char xdata FATBUF[512];
  12          //*****************************************************************
  13          //根据文件开始簇号计算文件的逻辑扇区号
  14          //计算公式: 开始逻辑扇区号=(蔟号-2)*每簇扇区数+数据区开始逻辑扇区号
  15          //入口参数: clusterNum 蔟号 
  16          unsigned long FirstSectorofCluster32(unsigned long 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 long ThisFatSecNum32(unsigned long clusterNum)
  26          {
  27   1         unsigned long temp;
  28   1         temp=clusterNum*4;
  29   1         temp=temp/DeviceInfo.BPB_BytesPerSec;
  30   1         temp=temp+DeviceInfo.FatStartSector;
  31   1         return temp;
  32   1      }
  33          
  34          unsigned long ThisFatEntOffset32(unsigned long clusterNum)
  35          {
  36   1              unsigned long temp1,temp2;
  37   1              temp1=4*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 long GetNextClusterNum32(unsigned long clusterNum)
  44          {
  45   1              unsigned long FatSecNum,FatEntOffset;
  46   1              
  47   1              FatSecNum=ThisFatSecNum32(clusterNum);
  48   1              FatEntOffset=ThisFatEntOffset32(clusterNum);
  49   1              if(ThisFile.FatSectorPointer!=FatSecNum)
  50   1              {       
  51   2                      
  52   2                      if(!RBC_Read(FatSecNum,1,FATBUF))
  53   2                              return 0xFFFFFFFF;
  54   2                      ThisFile.FatSectorPointer=FatSecNum;
  55   2              }
C51 COMPILER V7.07   FAT32                                                                 07/13/2007 21:38:27 PAGE 2   

  56   1              
  57   1              ///////////////////////////////////////////////////
  58   1              clusterNum=LSwapINT32(FATBUF[FatEntOffset],FATBUF[FatEntOffset+1],FATBUF[FatEntOffset+2],FATBUF[FatEntOff
             -set+3]);
  59   1              return clusterNum;
  60   1      }
  61          
  62          unsigned char GoToPointer32(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=GetNextClusterNum32(ThisFile.ClusterPointer);
  73   2                      if(ThisFile.ClusterPointer==0xffffffff)
  74   2                      {
  75   3                      return FALSE;
  76   3                      }
  77   2              }
  78   1              ThisFile.SectorofCluster=pointer/DeviceInfo.BPB_BytesPerSec;
  79   1              ThisFile.SectorPointer=FirstSectorofCluster32(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 DeleteClusterLink32(unsigned long clusterNum)
  87          {
  88   1              unsigned long FatSecNum,FatEntOffset;
  89   1              unsigned char i;
  90   1              while((clusterNum>1)&&(clusterNum<DeviceInfo.TotCluster))
  91   1              {
  92   2              FatSecNum=ThisFatSecNum32(clusterNum);
  93   2              FatEntOffset=ThisFatEntOffset32(clusterNum);
  94   2              if(RBC_Read(FatSecNum,1,DBUF))
  95   2                      clusterNum=LSwapINT32(DBUF[FatEntOffset],DBUF[FatEntOffset+1],DBUF[FatEntOffset+2],DBUF[FatEntOffset+3])
             -;
  96   2              else
  97   2                      return FALSE;
  98   2              DBUF[FatEntOffset]=0x00;DBUF[FatEntOffset+1]=0x00;DBUF[FatEntOffset+2]=0x00;DBUF[FatEntOffset+3]=0x00;                  
  99   2              for(i=0;i<DeviceInfo.BPB_NumFATs;i++)
 100   2                      {
 101   3                      DelayMs(5);
 102   3                      if(!RBC_Write(FatSecNum+i*DeviceInfo.BPB_FATSz32,1,DBUF))
 103   3                              return FALSE;
 104   3                      }       
 105   2              }
 106   1              return TRUE;
 107   1      }
 108          //
 109          unsigned long GetFreeCusterNum32(void)
 110          {
 111   1              unsigned long xdata clusterNum,i;
 112   1              unsigned long xdata sectorNum;
 113   1              unsigned char xdata j;
 114   1              clusterNum=0;
 115   1              sectorNum=DeviceInfo.FatStartSector;                                                     //文件分配表(FAT)开始扇区
C51 COMPILER V7.07   FAT32                                                                 07/13/2007 21:38:27 PAGE 3   

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


MODULE INFORMATION:   STATIC OVERLAYABLE
   CODE SIZE        =   2089    ----
   CONSTANT SIZE    =   ----    ----
   XDATA SIZE       =   ----      26
   PDATA SIZE       =   ----    ----
   DATA SIZE        =   ----      63
C51 COMPILER V7.07   FAT32                                                                 07/13/2007 21:38:27 PAGE 4   

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