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

📄 hpi.lst

📁 51单片机读写U盘
💻 LST
📖 第 1 页 / 共 4 页
字号:
 352   2                         /////////////////////////////////////////////////////////
 353   2                         if(ThisFile.OffsetofSector>DeviceInfo.BPB_BytesPerSec-1)
 354   2                         {    
 355   3                              ThisFile.OffsetofSector-=DeviceInfo.BPB_BytesPerSec;
 356   3                              ThisFile.SectorofCluster+=1;
 357   3                              if(ThisFile.SectorofCluster>DeviceInfo.BPB_SecPerClus-1)
 358   3                              {
 359   4                                      ThisFile.SectorofCluster=0;
 360   4                                       ThisFile.ClusterPointer=GetNextClusterNum(ThisFile.ClusterPointer);
 361   4                                       if(ThisFile.ClusterPointer>0xffef)
 362   4                                              {
 363   5                                                 //RspBlockReadFile.errcode=ERC_REACHEND;
 364   5                                                 //RspBlockReadFile.result=0x0;
 365   5                                                 UartRspBlock.errcode=ERC_REACHEND;
 366   5                                                 return FALSE;        
 367   5                                              }
 368   4                                       ThisFile.SectorPointer=FirstSectorofCluster(ThisFile.ClusterPointer);  
 369   4                              }
 370   3                              else
 371   3                                      ThisFile.SectorPointer=ThisFile.SectorPointer+1;
 372   3                          }
 373   2                         //////////////////////////////////////////////////////////////////
 374   2                      }//end while
 375   1              
C51 COMPILER V7.20   HPI                                                                   12/13/2005 15:28:00 PAGE 9   

 376   1              
 377   1              ThisFile.bFileOpen=1;
 378   1              ThisFile.pointer+=UartRspBlock.len;
 379   1              //////////////////////////////////////////////
 380   1              RspBlockReadFile.readLength=SwapINT16(UartRspBlock.len);
 381   1              return TRUE;
 382   1      #undef RspBlockReadFile
 383   1      }
 384          
 385          unsigned char CreateFile(unsigned char *pBuffer)
 386          {
 387   1      #define RspBlockCreateFile UartRspBlock.RspBlock.Rsp_CreateFile
 388   1              //unsigned long sectorNum;
 389   1              unsigned int sector,i,j;
 390   1              unsigned char bstop;
 391   1              PDIR_INFO pDirInfo;
 392   1              
 393   1              if(!bXXGFlags.bits.SLAVE_IS_ATTACHED)
 394   1              {
 395   2              UartRspBlock.errcode=ERC_NODEVICE;
 396   2              return FALSE;           
 397   2              }
 398   1              ///////////////////////////////////////////////////////////
 399   1              //RspBlockCreateFile.result=0x1;
 400   1              //RspBlockCreateFile.errcode=ERC_OK;
 401   1              pDirInfo=(PDIR_INFO)pBuffer;
 402   1              ///////// Search the file of the same name  ///////////
 403   1              //UartCmdBlock.CmdBlock.Cmd_CreateFile.filename[j]
 404   1              //if(!SPC_TestUnit())
 405   1              //      return FALSE;
 406   1              //if(!RBC_Read(1,1,DBUF))
 407   1              //      return FALSE;
 408   1              //if(!RBC_Write(1,1,DBUF))
 409   1              //      return FALSE;
 410   1              //////// Search the fat for a free cluster  ////////////
 411   1              pDirInfo->startCluster=SwapINT16(GetFreeCusterNum());
 412   1              
 413   1              if(pDirInfo->startCluster<0x2)
 414   1              {
 415   2              UartRspBlock.errcode=ERC_NODEVICE;
 416   2              return FALSE;           
 417   2              }
 418   1              pDirInfo->length=0;
 419   1              /////// Search a free space in the root dir space and build the item ///
 420   1              ThisFile.bFileOpen=0;
 421   1              bstop=0;
 422   1              for(sector=0;sector<DeviceInfo.BPB_RootEntCnt;sector++)
 423   1                  {   
 424   2                      //////////////////////////////////////////////////
 425   2                      if(!RBC_Read(DeviceInfo.RootStartSector+sector,1,DBUF))
 426   2                              {
 427   3                              
 428   3                              UartRspBlock.errcode=ERC_DEVICEERR;
 429   3                                      return FALSE;   
 430   3                              }
 431   2                      ///////////////////////////////////////////////////
 432   2                      for(i=0;i<DeviceInfo.BPB_BytesPerSec;i=i+32)
 433   2                              {
 434   3                              if((DBUF[i]==0x00)||(DBUF[i]==0xE5))
 435   3                                      {
 436   4                                      for(j=0;j<32;j++)
 437   4                                              //DBUF[i+j]=UartCmdBlock.CmdBlock.Cmd_CreateFile.item[j];
C51 COMPILER V7.20   HPI                                                                   12/13/2005 15:28:00 PAGE 10  

 438   4                                              DBUF[i+j]=*(pBuffer+j);
 439   4                                      if(!RBC_Write(DeviceInfo.RootStartSector+sector,1,DBUF))
 440   4                                              {
 441   5                                              UartRspBlock.errcode=ERC_DEVICEERR;
 442   5                                              return FALSE;   
 443   5                                              }
 444   4                                      bstop=1;
 445   4                                      break;
 446   4                                      }
 447   3                              }
 448   2                      ///////////////////////////////////////////////////////
 449   2                      if(bstop==1)break;
 450   2                      
 451   2                  }
 452   1              /////////////////////////////////////////////
 453   1              //pDirInfo=(PDIR_INFO)RspBlockOpenFile.item;
 454   1              //ThisFile.FatSectorPointer=ThisFatSecNum(ThisFile.StartCluster);
 455   1              ThisFile.StartCluster=SwapINT16(pDirInfo->startCluster);
 456   1              ThisFile.LengthInByte=0;
 457   1              ThisFile.ClusterPointer=ThisFile.StartCluster;
 458   1              ThisFile.SectorPointer=FirstSectorofCluster(ThisFile.StartCluster);
 459   1              ThisFile.OffsetofSector=0;
 460   1              ThisFile.SectorofCluster=0;
 461   1              ThisFile.bFileOpen=1;
 462   1              ThisFile.pointer=0;
 463   1              ThisFile.FatSectorPointer=0;
 464   1              //////////////////////////////////////////////
 465   1              return TRUE;
 466   1      #undef RspBlockCreateFile
 467   1      }
 468          
 469          unsigned char WriteFile(unsigned int writeLength,unsigned char *pBuffer)
 470          {
 471   1      #define RspBlockWriteFile UartRspBlock.RspBlock.Rsp_WriteFile
 472   1              unsigned int len,sector,i;
 473   1              PDIR_INFO pDirInfo;
 474   1              unsigned char bSuccess,bStop;
 475   1              
 476   1              if(!bXXGFlags.bits.SLAVE_IS_ATTACHED)
 477   1              {
 478   2              UartRspBlock.errcode=ERC_NODEVICE;
 479   2              return FALSE;           
 480   2              }
 481   1              if(!ThisFile.bFileOpen)
 482   1              {
 483   2              UartRspBlock.errcode=ERC_FILENOTOPENED;
 484   2              return FALSE;           
 485   2              }
 486   1              ///////////////////////////////////////////////////////////
 487   1              //if(UartCmdBlock.CmdBlock.Cmd_WriteFile.writeLength>0)
 488   1              //      {
 489   1              //      for(i=UartCmdBlock.CmdBlock.Cmd_WriteFile.writeLength;i<MAX_WRITE_LENGTH;i++)
 490   1              //      UARTBUF[i]=0;
 491   1              //      }
 492   1              ///////////////////////////////////////////////////////////
 493   1              ThisFile.bFileOpen=0;
 494   1              bSuccess=1;
 495   1              bStop=0;
 496   1      
 497   1              UartRspBlock.len=0;
 498   1              //if(UartCmdBlock.CmdBlock.Cmd_WriteFile.writeLength)
 499   1              while(writeLength>0)
C51 COMPILER V7.20   HPI                                                                   12/13/2005 15:28:00 PAGE 11  

 500   1              {
 501   2                      if(writeLength+ThisFile.OffsetofSector>DeviceInfo.BPB_BytesPerSec)
 502   2                              len=DeviceInfo.BPB_BytesPerSec;
 503   2                      else
 504   2                              len=writeLength+ThisFile.OffsetofSector;
 505   2                         
 506   2                       //////////////////////////////////////////////////////
 507   2                       if(ThisFile.OffsetofSector>0)
 508   2                              {
 509   3                              if(RBC_Read(ThisFile.SectorPointer,1,DBUF))
 510   3                                      {
 511   4                                      //ThisFile.OffsetofSector=len;
 512   4                                      len=len-ThisFile.OffsetofSector;
 513   4                                      for(i=0;i<len;i++)
 514   4                                              //DBUF[ThisFile.OffsetofSector+i]=UARTBUF[i];
 515   4                                              DBUF[ThisFile.OffsetofSector+i]=*(pBuffer+i);
 516   4                                      if(!RBC_Write(ThisFile.SectorPointer,1,DBUF))
 517   4                                              {
 518   5                                              UartRspBlock.errcode=ERC_DEVICEERR;
 519   5                                              return FALSE;   
 520   5                                              }
 521   4                                      ThisFile.OffsetofSector=ThisFile.OffsetofSector+len;
 522   4                                      }
 523   3                              else
 524   3                                      {
 525   4                                      UartRspBlock.errcode=ERC_DEVICEERR;
 526   4                                      return FALSE;   
 527   4                                      }
 528   3                              }
 529   2                       else
 530   2                              {
 531   3                              if(!RBC_Write(ThisFile.SectorPointer,1,pBuffer+UartRspBlock.len))
 532   3                                      {
 533   4                                      UartRspBlock.errcode=ERC_DEVICEERR;
 534   4                                      return FALSE;   
 535   4                                      }
 536   3                              ThisFile.OffsetofSector=len;
 537   3                              }
 538   2                       /////////////////////////////////////////////////////
 539   2                       //if(ThisFile.OffsetofSector>DeviceInfo.BPB_BytesPerSec-1)
 540   2                       //     ThisFile.OffsetofSector-=DeviceInfo.BPB_BytesPerSec;
 541   2                         writeLength-=len;
 542   2                         UartRspBlock.len+=len;
 543   2                         //ThisFile.LengthInByte+=len;
 544   2                      /////////////更新文件指针 //////////////////////////////
 545   2                        if(ThisFile.OffsetofSector>DeviceInfo.BPB_BytesPerSec-1)
 546   2                         {    
 547   3                              ThisFile.OffsetofSector-=DeviceInfo.BPB_BytesPerSec;
 548   3                              ThisFile.SectorofCluster+=1;
 549   3                              if(ThisFile.SectorofCluster>DeviceInfo.BPB_SecPerClus-1)
 550   3                              {
 551   4                                      ThisFile.SectorofCluster=0;
 552   4                                       ThisFile.ClusterPointer=CreateClusterLink(ThisFile.ClusterPointer);//GetNextClusterNum(ThisFile.Clus
             -terPointer);
 553   4                                       if(ThisFile.ClusterPointer==0x00)
 554   4                                              {
 555   5                                       //        RspBlockReadFile.errcode=ERC_REACHEND;
 556   5                                              //   RspBlockReadFile.result=0x0;
 557   5                                              UartRspBlock.errcode=ERC_DEVICEERR;
 558   5                                              return FALSE;   
 559   5                                              }
 560   4                                       ThisFile.SectorPointer=FirstSectorofCluster(ThisFile.ClusterPointer);  
C51 COMPILER V7.20   HPI                                                                   12/13/2005 15:28:00 PAGE 12  

 561   4                              }
 562   3                              else
 563   3                                      ThisFile.SectorPointer=ThisFile.SectorPointer+1;
 564   3                          }
 565   2                      
 566   2              
 567   2              }//end while
 568   1              ThisFile.pointer+=UartRspBlock.len;
 569   1              ///////////更新文件目录信息/////////////////////////////
 570   1              if(bSuccess==1)
 571   1              {
 572   2                      
 573   2                      for(sector=0;sector<DeviceInfo.BPB_RootEntCnt;sector++)
 574   2                      {   
 575   3                      //////////////////////////////////////////////////
 576   3                      if(!RBC_Read(DeviceInfo.RootStartSector+sector,1,DBUF))
 577   3                              {
 578   4                              UartRspBlock.errcode=ERC_DEVICEERR;
 579   4                              return FALSE;   
 580   4                              }
 581   3                      ///////////////////////////////////////////////////
 582   3                      for(i=0;i<DeviceInfo.BPB_BytesPerSec;i=i+32)
 583   3                              {
 584   4                              pDirInfo=(PDIR_INFO)(DBUF+i);
 585   4                              
 586   4                              if(pDirInfo->startCluster==SwapINT16(ThisFile.StartCluster))

⌨️ 快捷键说明

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