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

📄 hpi.lst

📁 能用51读写U盘...创建文件格式...能自由创建文件.删除.读写
💻 LST
📖 第 1 页 / 共 5 页
字号:
 853   3                      
 854   3                     }//end search
 855   2              if(sector>=DeviceInfo.BPB_RootEntCnt)
 856   2                      return FALSE;   
 857   2              }
 858   1              else
 859   1              {
 860   2              NowCluster=DirStartCluster;             
C51 COMPILER V7.06   HPI                                                                   08/10/2005 23:25:28 PAGE 15  

 861   2                      do
 862   2                      {
 863   3                              NowSector=FirstSectorofCluster(NowCluster);
 864   3                              for(sector=0;sector<DeviceInfo.BPB_SecPerClus;sector++)
 865   3                      {   
 866   4                                      if(!RBC_Read(NowSector+sector,1,DBUF))
 867   4                                              return FALSE;                           
 868   4                                      for(i=0;i<DeviceInfo.BPB_BytesPerSec;i=i+32)
 869   4                                      {
 870   5                                              if(DBUF[i]==0x00)
 871   5                                                      return FALSE;
 872   5                                              j=0;
 873   5                                              while(DBUF[i+j]==*(pBuffer+j))
 874   5                                              {
 875   6                                                       j=j+1;
 876   6                                                       if(j>10)
 877   6                                                              break;
 878   6                                              }
 879   5                                              if(j>10)
 880   5                                              { 
 881   6                                                      DBUF[i]=0xE5;
 882   6                                                      ThisFile.StartCluster=LSwapINT16(DBUF[i+26],DBUF[i+27]);
 883   6                                                      for(k=(i-32);k>=0;k=k-32)
 884   6                                                      {
 885   7                                                      if(DBUF[k+11]==0x0F)
 886   7                                                              DBUF[k]=0xE5;
 887   7                                                      else
 888   7                                                              break;
 889   7                                                      }
 890   6                                                      DelayMs(15);
 891   6                                                      if(!RBC_Write(NowSector+sector,1,DBUF))
 892   6                                                              return FALSE;                                   
 893   6                                      //////////////////// 清除FAT中的纪录////////////////////////
 894   6                                                      DelayMs(10);
 895   6                                                      if(!DeleteClusterLink(ThisFile.StartCluster))
 896   6                                                              return FALSE;                                   
 897   6                                                      bStop=1;
 898   6                                                      break;
 899   6                                                      }
 900   5                                      }
 901   4                                      if(bStop==1)break;              
 902   4                      }
 903   3                              if(bStop==1)break;      
 904   3                              NowCluster=GetNextClusterNum(NowCluster);                       
 905   3                      }while(NowCluster<=0xffef);
 906   2                      
 907   2                      if(NowCluster>0xffef)
 908   2                      return FALSE;
 909   2              }
 910   1              return TRUE;
 911   1      }
 912          
 913          unsigned char GetCapacity(void)
 914          {
 915   1              unsigned int sectorNum,i;       
 916   1              unsigned long FreeSize,Freesectorcnt;
 917   1      
 918   1              if(!bFlags.bits.SLAVE_IS_ATTACHED)
 919   1                      return FALSE;
 920   1                      
 921   1              ////////////////////////////////////////////////////////////////////////
 922   1              sectorNum=DeviceInfo.FatStartSector;
C51 COMPILER V7.06   HPI                                                                   08/10/2005 23:25:28 PAGE 16  

 923   1              Freesectorcnt=0;
 924   1              while(sectorNum<DeviceInfo.BPB_FATSz16+DeviceInfo.FatStartSector)
 925   1              {
 926   2                      
 927   2                      if(RBC_Read(sectorNum,1,DBUF))
 928   2                      {
 929   3                        for(i=0;i<DeviceInfo.BPB_BytesPerSec;i=i+2)
 930   3                              {                        
 931   4                               if((DBUF[i]==0x00)&&(DBUF[i+1]==0x00))
 932   4                                      {       
 933   5                                      Freesectorcnt++;
 934   5                                      }         
 935   4                              }       
 936   3                      }
 937   2                      else                    
 938   2                              return FALSE;                   
 939   2                      sectorNum++;
 940   2              }
 941   1              
 942   1              ////////////////////////////////////////////////////////////////////////
 943   1              FreeSize=DeviceInfo.BPB_BytesPerSec*DeviceInfo.BPB_SecPerClus;
 944   1              FreeSize=Freesectorcnt*FreeSize;
 945   1              
 946   1              UARTBUF[0]=(unsigned char)((FreeSize>>24)&0xff);
 947   1              UARTBUF[1]=(unsigned char)((FreeSize>>16)&0xff);
 948   1              UARTBUF[2]=(unsigned char)((FreeSize>>8)&0xff);
 949   1              UARTBUF[3]=(unsigned char)(FreeSize&0xff);
 950   1              Response.len=4;
 951   1              return TRUE;
 952   1      }
 953          
 954          unsigned char CreateDir(unsigned long len,unsigned char *pBuffer,unsigned char *pName)
 955          {
 956   1              unsigned int sector,i,j,DirCount;
 957   1              unsigned int cnum,ClusterPointer;
 958   1              unsigned char xdata bstop,InByte,bwrite;
 959   1              
 960   1              if(!bFlags.bits.SLAVE_IS_ATTACHED)
 961   1                      return FALSE;
 962   1              if((len%32)!=0)
 963   1                      return FALSE;
 964   1              if((len+32)>DeviceInfo.BPB_BytesPerSec)
 965   1                      return FALSE;
 966   1      
 967   1              ThisFile.bFileOpen=0;
 968   1              ThisFile.FatSectorPointer=0;
 969   1      
 970   1              cnum=GetFreeCusterNum();
 971   1              if(cnum<0x02)
 972   1                      return FALSE;   
 973   1      
 974   1              pBuffer[11]=0x10;
 975   1              pBuffer[26]=(unsigned char)(cnum);
 976   1              pBuffer[27]=(unsigned char)(cnum>>8);
 977   1              pBuffer[28]=0;pBuffer[29]=0;pBuffer[30]=0;pBuffer[31]=0;
 978   1              bstop=0;
 979   1      
 980   1              if(DirStartCluster==0)  
 981   1              {
 982   2              /////// Search a free space in the root dir space and build the item ///
 983   2              for(sector=0;sector<DeviceInfo.BPB_RootEntCnt;sector++)
 984   2                  {   
C51 COMPILER V7.06   HPI                                                                   08/10/2005 23:25:28 PAGE 17  

 985   3                      if(!RBC_Read(DeviceInfo.RootStartSector+sector,1,DBUF))
 986   3                              return FALSE;   
 987   3                      DirCount=0;bwrite=0;
 988   3                      for(i=0;i<DeviceInfo.BPB_BytesPerSec;i=i+32)
 989   3                              {
 990   4                              if(len==0)
 991   4                                      {
 992   5                                      if((DBUF[i]==0x00)||(DBUF[i]==0xE5))
 993   5                                      {
 994   6                                      for(j=0;j<32;j++)
 995   6                                              DBUF[i+j]=*(pBuffer+j);
 996   6                                      if(!RBC_Write(DeviceInfo.RootStartSector+sector,1,DBUF))
 997   6                                              return FALSE;                                   
 998   6                                      bstop=1;
 999   6                                      break;
1000   6                                      }
1001   5                                      }
1002   4                              else
1003   4                              {
1004   5                              if(DirCount==0)
1005   5                                      InByte=i;
1006   5                              if(DBUF[i]==0xE5)                               
1007   5                                      DirCount++;                             
1008   5                              else if(DBUF[i]==0x00)
1009   5                                      {       
1010   6                                      DirCount++;     
1011   6                                      DBUF[i]=0xE5;   
1012   6                                      bwrite=1;                       
1013   6                                      }
1014   5                              else
1015   5                                      DirCount=0;
1016   5      
1017   5                              if((DirCount*32)>=(len+32))
1018   5                                      {
1019   6                                      for(j=0;j<len;j++)
1020   6                                              DBUF[InByte+j]=*(pName+j);
1021   6      
1022   6                                      for(j=0;j<32;j++)
1023   6                                              DBUF[InByte+len+j]=*(pBuffer+j);
1024   6      
1025   6                                      if(!RBC_Write(DeviceInfo.RootStartSector+sector,1,DBUF))
1026   6                                              return FALSE;                                   
1027   6                                      bstop=1;
1028   6                                      break;
1029   6                                      }
1030   5                               }
1031   4                              }               
1032   3                      if(bstop==1)break;      
1033   3      
1034   3                      if((len!=0)&&(bwrite==1))
1035   3                              {
1036   4                              if(!RBC_Write(DeviceInfo.RootStartSector+sector,1,DBUF))
1037   4                                      return FALSE;
1038   4                      }
1039   3                  }
1040   2      
1041   2              if(sector>=DeviceInfo.BPB_RootEntCnt)
1042   2                      return FALSE;
1043   2              }
1044   1      ////////////////////////////////////////////////////////////
1045   1              else
1046   1              {
C51 COMPILER V7.06   HPI                                                                   08/10/2005 23:25:28 PAGE 18  

1047   2                      NowCluster=DirStartCluster;             
1048   2                      do
1049   2                      {
1050   3                              NowSector=FirstSectorofCluster(NowCluster);
1051   3                              ClusterPointer=NowCluster;
1052   3                              for(sector=0;sector<DeviceInfo.BPB_SecPerClus;sector++)
1053   3                      {   
1054   4                                      if(!RBC_Read(NowSector+sector,1,DBUF))
1055   4                                              return FALSE;
1056   4                                      DirCount=0;
1057   4                                      for(i=0;i<DeviceInfo.BPB_BytesPerSec;i=i+32)
1058   4                                      {
1059   5                                      if(len==0)
1060   5                                              {
1061   6                                              if((DBUF[i]==0x00)||(DBUF[i]==0xE5))
1062   6                                              {
1063   7                                              for(j=0;j<32;j++)
1064   7                                                      DBUF[i+j]=*(pBuffer+j);
1065   7                                              if(!RBC_Write(NowS

⌨️ 快捷键说明

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