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

📄 fat.lst

📁 单片机读写u盘的完整程序,代码全部用c语言编写。非常有价值的程序。这是本人花2500元购买的开发板源吗
💻 LST
📖 第 1 页 / 共 2 页
字号:
C51 COMPILER V6.21  FAT                                                                    06/13/2005 16:14:57 PAGE 1   


C51 COMPILER V6.21, COMPILATION OF MODULE FAT
OBJECT MODULE PLACED IN Fat.OBJ
COMPILER INVOKED BY: g:\Keil_run\C51\BIN\C51.EXE Fat.c BROWSE DEBUG OBJECTEXTEND

stmt level    source

   1          #include "common.h"
   2          #include "Fat.h"
   3          #include "SL811.H"
   4          #include "TPBULK.H"
   5          #include "HAL.H"
   6          //#include "RBCCMD.H"
   7          ////////////////////////////////////////
   8          extern XXGFLAGS bdata bXXGFlags;
   9          extern SYS_INFO_BLOCK xdata DeviceInfo;
  10          extern FILE_INFO xdata ThisFile;
  11          extern unsigned char xdata DBUF[BUFFER_LENGTH];
  12          unsigned char xdata FATBUF[512];
  13          unsigned char xdata CurFatSector[512];
  14          //unsigned char xdata OldFatSector[512];
  15          FREE_FAT_INFO xdata FreeFat;
  16          ////////////////////////////////////////
  17          unsigned long FirstSectorofCluster(unsigned int clusterNum)
  18          {
  19   1              unsigned long temp;
  20   1              temp=clusterNum-2;
  21   1              temp=temp*DeviceInfo.BPB_SecPerClus;
  22   1              temp=temp+DeviceInfo.FirstDataSector;
  23   1              return temp;
  24   1      }
  25          
  26          unsigned int ThisFatSecNum(unsigned int clusterNum)
  27          {
  28   1         unsigned int temp;
  29   1         temp=clusterNum*2;
  30   1         temp=temp/DeviceInfo.BPB_BytesPerSec;
  31   1         temp=temp+DeviceInfo.FatStartSector;
  32   1         return temp;
  33   1      }
  34          
  35          unsigned int ThisFatEntOffset(unsigned int clusterNum)
  36          {
  37   1              unsigned int temp1,temp2;
  38   1              temp1=2*clusterNum;
  39   1              temp2=temp1/DeviceInfo.BPB_BytesPerSec;
  40   1              temp1=temp1-temp2*DeviceInfo.BPB_BytesPerSec;
  41   1              return temp1;
  42   1      }
  43          
  44          unsigned int GetNextClusterNum(unsigned int clusterNum)
  45          {
  46   1              unsigned int xxgFatSecNum,xxgFatEntOffset;
  47   1              
  48   1              xxgFatSecNum=ThisFatSecNum(clusterNum);
  49   1              xxgFatEntOffset=ThisFatEntOffset(clusterNum);
  50   1              //ThisFile.FatSectorPointer=xxgFatSecNum;
  51   1              if(ThisFile.FatSectorPointer!=xxgFatSecNum)
  52   1              {       
  53   2                      
  54   2                      if(!RBC_Read(xxgFatSecNum,1,FATBUF))
  55   2                              return 0xFFFF;
C51 COMPILER V6.21  FAT                                                                    06/13/2005 16:14:57 PAGE 2   

  56   2                      ThisFile.FatSectorPointer=xxgFatSecNum;
  57   2              }
  58   1              
  59   1              ///////////////////////////////////////////////////
  60   1              clusterNum=FATBUF[xxgFatEntOffset+1];
  61   1              clusterNum=clusterNum<<8;
  62   1              clusterNum+=FATBUF[xxgFatEntOffset];    
  63   1              return clusterNum;
  64   1      }
  65          
  66          unsigned char DeleteClusterLink(unsigned int clusterNum)
  67          {
  68   1              //unsigned int nextClusterNum;
  69   1              unsigned int xxgFatSecNum,xxgFatEntOffset;
  70   1              //nextClusterNum=GetNextClusterNum(clusterNum);
  71   1              ////////////////////////////////////////////
  72   1              //nextClusterNum=clusterNum;
  73   1              while((clusterNum>1)&&(clusterNum<0xfff0))
  74   1              {
  75   2              xxgFatSecNum=ThisFatSecNum(clusterNum);
  76   2              xxgFatEntOffset=ThisFatEntOffset(clusterNum);
  77   2              if(RBC_Read(xxgFatSecNum,1,DBUF))
  78   2                      {
  79   3                      clusterNum=DBUF[xxgFatEntOffset+1];
  80   3                      clusterNum=clusterNum<<8;
  81   3                      clusterNum+=DBUF[xxgFatEntOffset];      
  82   3                      //return clusterNum;
  83   3                      }
  84   2              else
  85   2                      return FALSE;
  86   2              DBUF[xxgFatEntOffset]=0x00;
  87   2              DBUF[xxgFatEntOffset+1]=0x00;   
  88   2              //DelayMs(5);
  89   2              if(!RBC_Write(xxgFatSecNum,1,DBUF))
  90   2                      return FALSE;
  91   2              //DelayMs(5);
  92   2              if(!RBC_Write(xxgFatSecNum+DeviceInfo.BPB_FATSz16,1,DBUF))
  93   2                      return FALSE;
  94   2              ////////////////////////////////////////////
  95   2              }
  96   1              return TRUE;
  97   1      }
  98          
  99          unsigned int GetClusterNumFromSectorNum(unsigned long sectorNum)
 100          {
 101   1              unsigned long temp;
 102   1              temp=sectorNum-DeviceInfo.FirstDataSector;
 103   1              temp=temp/DeviceInfo.BPB_SecPerClus;
 104   1              temp=temp+2;
 105   1              return (unsigned int)temp;
 106   1      }
 107          /*
 108          unsigned long GetSecNumFromPointer(void)
 109          {
 110                  unsigned int clusterNum,clusterSize;
 111                  unsigned long temp,pointer;
 112                  pointer=ThisFile.FilePointer;
 113                  clusterSize=DeviceInfo.BPB_SecPerClus*DeviceInfo.BPB_BytesPerSec;
 114                  clusterNum=ThisFile.StartCluster;
 115                  while(pointer>clusterSize)
 116                  {
 117                          pointer-=clusterSize;   
C51 COMPILER V6.21  FAT                                                                    06/13/2005 16:14:57 PAGE 3   

 118                          clusterNum=GetNextClusterNum(clusterNum);
 119                  }
 120                  temp=FirstSectorofCluster(clusterNum)+pointer/DeviceInfo.BPB_BytesPerSec;
 121                  return temp;
 122          }
 123          */
 124          unsigned char GoToPointer(unsigned long pointer)
 125          {
 126   1              //unsigned char temp;
 127   1              unsigned int clusterSize;
 128   1              //unsigned long temp;
 129   1              //pointer=ThisFile.FilePointer;
 130   1              clusterSize=DeviceInfo.BPB_SecPerClus*DeviceInfo.BPB_BytesPerSec;
 131   1              ThisFile.ClusterPointer=ThisFile.StartCluster;
 132   1              while(pointer>clusterSize)
 133   1              {
 134   2                      pointer-=clusterSize;   
 135   2                      ThisFile.ClusterPointer=GetNextClusterNum(ThisFile.ClusterPointer);
 136   2                      if(ThisFile.ClusterPointer==0xffff)
 137   2                      {
 138   3                      return FALSE;
 139   3                      }
 140   2              }
 141   1              ThisFile.SectorofCluster=pointer/DeviceInfo.BPB_BytesPerSec;
 142   1              ThisFile.SectorPointer=FirstSectorofCluster(ThisFile.ClusterPointer)+ThisFile.SectorofCluster;
 143   1              ThisFile.OffsetofSector=pointer-ThisFile.SectorofCluster*DeviceInfo.BPB_BytesPerSec;
 144   1              ThisFile.FatSectorPointer=0;
 145   1              return TRUE;
 146   1              
 147   1      }
 148          
 149          unsigned int GetFreeCusterNum(void)
 150          {

⌨️ 快捷键说明

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