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

📄 hpi.lst

📁 单片机读写U盘程序
💻 LST
📖 第 1 页 / 共 5 页
字号:
 637   1              if(!bFlags.bits.SLAVE_IS_ATTACHED)
 638   1                      return FALSE;           
 639   1              if(!ThisFile.bFileOpen)
 640   1                      return FALSE;
 641   1              ThisFile.bFileOpen=0;
 642   1              bSuccess=1;
 643   1              bStop=0;
 644   1              tlen=0;
 645   1      
 646   1              while(writeLength>0)
 647   1              {
 648   2                      if(writeLength+ThisFile.OffsetofSector>DeviceInfo.BPB_BytesPerSec)
 649   2                              len=DeviceInfo.BPB_BytesPerSec;
 650   2                      else
 651   2                              len=writeLength+ThisFile.OffsetofSector;
 652   2                         
 653   2                       //////////////////////////////////////////////////////
 654   2                       if(ThisFile.OffsetofSector>0)
 655   2                              {
 656   3                              if(RBC_Read(ThisFile.SectorPointer,1,DBUF))
 657   3                                      {
 658   4                                      
 659   4                                      len=len-ThisFile.OffsetofSector;
 660   4                                      for(i=0;i<len;i++)
 661   4                                              
 662   4                                              DBUF[ThisFile.OffsetofSector+i]=*(pBuffer+i);
 663   4                                      if(!RBC_Write(ThisFile.SectorPointer,1,DBUF))
 664   4                                              return FALSE;                                           
 665   4                                      ThisFile.OffsetofSector=ThisFile.OffsetofSector+len;
 666   4                                      }
 667   3                              else
 668   3                                      return FALSE;                           
 669   3                              }
 670   2                       else
 671   2                              {
 672   3                              if(!RBC_Write(ThisFile.SectorPointer,1,pBuffer+tlen))
 673   3                                      return FALSE;                           
 674   3                              ThisFile.OffsetofSector=len;
C51 COMPILER V7.07   HPI                                                                   04/02/2009 22:39:37 PAGE 12  

 675   3                              }
 676   2                       /////////////////////////////////////////////////////
 677   2                         writeLength-=len;
 678   2                         tlen+=len;
 679   2                       /////////////更新文件指针 //////////////////////////////
 680   2                        if(ThisFile.OffsetofSector>DeviceInfo.BPB_BytesPerSec-1)
 681   2                         {    
 682   3                              ThisFile.OffsetofSector-=DeviceInfo.BPB_BytesPerSec;
 683   3                              ThisFile.SectorofCluster+=1;
 684   3                              if(ThisFile.SectorofCluster>DeviceInfo.BPB_SecPerClus-1)
 685   3                              {
 686   4                                      ThisFile.SectorofCluster=0;
 687   4                                       ThisFile.ClusterPointer=CreateClusterLink(ThisFile.ClusterPointer);
 688   4                                       if(ThisFile.ClusterPointer==0x00)
 689   4                                              return FALSE;                           
 690   4                                       ThisFile.SectorPointer=FirstSectorofCluster(ThisFile.ClusterPointer);  
 691   4                              }
 692   3                              else
 693   3                                      ThisFile.SectorPointer=ThisFile.SectorPointer+1;
 694   3                          }
 695   2                      
 696   2              
 697   2              }//end while
 698   1              ThisFile.pointer+=tlen;
 699   1              ///////////更新文件目录信息/////////////////////////////
 700   1              if(bSuccess==1)
 701   1              {
 702   2                      if(DirStartCluster==0)  
 703   2                      {
 704   3                      for(sector=0;sector<DeviceInfo.BPB_RootEntCnt;sector++)
 705   3                      {   
 706   4                      //////////////////////////////////////////////////
 707   4                      if(!RBC_Read(DeviceInfo.RootStartSector+sector,1,DBUF))
 708   4                              return FALSE;                           
 709   4                      ///////////////////////////////////////////////////
 710   4                      for(i=0;i<DeviceInfo.BPB_BytesPerSec;i=i+32)
 711   4                              {
 712   5                              cnum=LSwapINT16(DBUF[i+26],DBUF[i+27]);
 713   5                              if((cnum==ThisFile.StartCluster)&&(DBUF[i]!=0xe5))
 714   5                                      {
 715   6                                      if(ThisFile.pointer>ThisFile.LengthInByte)
 716   6                                              ThisFile.LengthInByte=ThisFile.pointer;                         
 717   6                                      DBUF[i+28]=(unsigned char)(ThisFile.LengthInByte&0xff);
 718   6                                      DBUF[i+29]=(unsigned char)((ThisFile.LengthInByte>>8)&0xff);
 719   6                                      DBUF[i+30]=(unsigned char)((ThisFile.LengthInByte>>16)&0xff);
 720   6                                      DBUF[i+31]=(unsigned char)((ThisFile.LengthInByte>>24)&0xff);
 721   6                                      if(!RBC_Write(DeviceInfo.RootStartSector+sector,1,DBUF))
 722   6                                              return FALSE;                   
 723   6                                       bStop=1;
 724   6                                       break;
 725   6                                      }
 726   5                              }
 727   4                      if(bStop==1)
 728   4                              break;          
 729   4                     }
 730   3                      }
 731   2      //////////////////////////////////////////////////////////////////////////////
 732   2                      else
 733   2                      {
 734   3                              NowCluster=DirStartCluster;             
 735   3                              do
 736   3                              {
C51 COMPILER V7.07   HPI                                                                   04/02/2009 22:39:37 PAGE 13  

 737   4                                      NowSector=FirstSectorofCluster(NowCluster);
 738   4                                      for(sector=0;sector<DeviceInfo.BPB_SecPerClus;sector++)
 739   4                                      {   
 740   5                                              if(!RBC_Read(NowSector+sector,1,DBUF))
 741   5                                                      return FALSE;                           
 742   5                                              for(i=0;i<DeviceInfo.BPB_BytesPerSec;i=i+32)
 743   5                                              {
 744   6                                                      cnum=LSwapINT16(DBUF[i+26],DBUF[i+27]);
 745   6                                                      if((cnum==ThisFile.StartCluster)&&(DBUF[i]!=0xe5))
 746   6                                                              {
 747   7                                                              if(ThisFile.pointer>ThisFile.LengthInByte)
 748   7                                                                      ThisFile.LengthInByte=ThisFile.pointer;                         
 749   7                                                              DBUF[i+28]=(unsigned char)(ThisFile.LengthInByte&0xff);
 750   7                                                              DBUF[i+29]=(unsigned char)((ThisFile.LengthInByte>>8)&0xff);
 751   7                                                              DBUF[i+30]=(unsigned char)((ThisFile.LengthInByte>>16)&0xff);
 752   7                                                              DBUF[i+31]=(unsigned char)((ThisFile.LengthInByte>>24)&0xff);
 753   7                                                              if(!RBC_Write(NowSector+sector,1,DBUF))
 754   7                                                                      return FALSE;                   
 755   7                                                               bStop=1;
 756   7                                                               break;
 757   7                                                              }                                                       
 758   6                                      }
 759   5                                              if(bStop==1)break;
 760   5                                      }
 761   4                                      if(bStop==1)break;
 762   4                                      NowCluster=GetNextClusterNum(NowCluster);                       
 763   4                              }while(NowCluster<=0xffef);
 764   3                      
 765   3                      if(NowCluster>0xffef)
 766   3                      return FALSE;
 767   3                      }
 768   2              }
 769   1              
 770   1              ThisFile.bFileOpen=1;
 771   1              //////////////////////////////////////////////
 772   1              return TRUE;
 773   1      }
 774          
 775          unsigned char RemoveFile(unsigned char *pBuffer)
 776          {
 777   1              unsigned int sector,i;
 778   1              unsigned char bStop,j;
 779   1              int k;
 780   1                      
 781   1              if(!bFlags.bits.SLAVE_IS_ATTACHED)
 782   1                      return FALSE;           
 783   1              if(DirStartCluster==0)  
 784   1              {
 785   2              ////////////// 清除目录/////////////////////////////////////
 786   2              for(sector=0;sector<DeviceInfo.BPB_RootEntCnt;sector++)
 787   2                      {   
 788   3                      //////////////////////////////////////////////////
 789   3                      if(!RBC_Read(DeviceInfo.RootStartSector+sector,1,DBUF))
 790   3                              return FALSE;                   
 791   3                      ///////////////////////////////////////////////////
 792   3                      for(i=0;i<DeviceInfo.BPB_BytesPerSec;i=i+32)
 793   3                              {
 794   4                              if(DBUF[i]==0x00)
 795   4                                      return FALSE;                   
 796   4                              ///////////////////////////////////////////
 797   4                              j=0;
 798   4                              while(DBUF[i+j]==*(pBuffer+j))
C51 COMPILER V7.07   HPI                                                                   04/02/2009 22:39:37 PAGE 14  

 799   4                                      {
 800   5                                       j=j+1;
 801   5                                       if(j>10) break;
 802   5                                       }
 803   4                              
 804   4                              if(j>10)
 805   4                                      {       
 806   5                                      DBUF[i]=0xE5;
 807   5                                      ThisFile.StartCluster=LSwapINT16(DBUF[i+26],DBUF[i+27]);
 808   5                              
 809   5                                      for(k=(i-32);k>=0;k=k-32)
 810   5                                              {
 811   6                                              if(DBUF[k+11]==0x0F)
 812   6                                                      DBUF[k]=0xE5;
 813   6                                              else
 814   6                                                      break;
 815   6                                              }
 816   5                                      DelayMs(15);
 817   5                                      if(!RBC_Write(DeviceInfo.RootStartSector+sector,1,DBUF))
 818   5                                              return FALSE;
 819   5      /*
 820   5                                      k=sector-1;
 821   5                                      if(k>=0)
 822   5                                              {
 823   5                                              if(!RBC_Read(DeviceInfo.RootStartSector+k,1,DBUF))
 824   5                                                      return FALSE;   
 825   5                                              for(k=DeviceInfo.BPB_BytesPerSec;k>=0;k=k-32)
 826   5                                                      {
 827   5                                                      if(DBUF[k+11]==0x0F)
 828   5                                                              DBUF[k]=0xE5;
 829   5                                                      else
 830   5                                                              break;
 831   5                                                      }
 832   5                                      //      DelayMs(15);
 833   5                                              if(!RBC_Write(DeviceInfo.RootStartSector+sector-1,1,DBUF))
 834   5                                                      return FALSE;
 835   5                                              }
 836   5      */                      
 837   5                                      //////////////////// 清除FAT中的纪录////////////////////////
 838   5                                      DelayMs(10);
 839   5                                      if(!DeleteClusterLink(ThisFile.StartCluster))
 840   5                                              return FALSE;                                   
 841   5                                      bStop=1;
 842   5                                      break;
 843   5                                      }
 844   4                              
 845   4                              }//end for
 846   3                      if(bStop==1)
 847   3                              break;
 848   3                      
 849   3                     }//end search
 850   2              if(sector>=DeviceInfo.BPB_RootEntCnt)
 851   2                      return FALSE;   
 852   2              }

⌨️ 快捷键说明

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