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

📄 hpi.lst

📁 单片机读写u盘的完整程序,代码全部用c语言编写。非常有价值的程序。这是本人花2500元购买的开发板源吗
💻 LST
📖 第 1 页 / 共 4 页
字号:
 213   3                              
 214   3                              }
 215   2                      ///////////////////////////////////////////////////
 216   2                      for(i=0;i<DeviceInfo.BPB_BytesPerSec;i=i+32)
 217   2                              {
 218   3                              if(DBUF[i]==0x00)
 219   3                                      {
 220   4                                      UartRspBlock.errcode=ERC_FILENOTFOUND;
 221   4                                      //UartRspBlock.errcode=ERC_DEVICEERR;
 222   4                                      return FALSE;   
 223   4                                      }
 224   3                              ///////////////////////////////////////////
 225   3                              j=0;
 226   3                              while(DBUF[i+j]==*(pBuffer+j))
 227   3                                      {
 228   4                                       j=j+1;
 229   4                                       if(j>10)
 230   4                                              break;
 231   4                                      }
 232   3                              
 233   3                              if(j>10)
 234   3                                  {
 235   4                                  for(j=0;j<32;j++)
 236   4                                      RspBlockOpenFile.item[j]=DBUF[i+j];
 237   4                                  //RspBlockOpenFile.result=0x1;
 238   4                                  ThisFile.bFileOpen=1;
 239   4                                  bstop=1;
 240   4                                   break;}
 241   3                              
C51 COMPILER V6.21  HPI                                                                    06/13/2005 16:14:56 PAGE 5   

 242   3                              }
 243   2                      ///////////////////////////////////////////////////////
 244   2                      if(bstop==1)break;
 245   2                      ///////////////////////////////////////////////////////
 246   2                      //if(DeviceInfo.BPB_RootEntCnt)
 247   2                      
 248   2                  }
 249   1                  
 250   1                  if(sector>=DeviceInfo.BPB_RootEntCnt)
 251   1                      {
 252   2                      UartRspBlock.errcode=ERC_FILENOTFOUND;
 253   2                      //UartRspBlock.errcode=ERC_DEVICEERR;
 254   2                      return FALSE;           
 255   2                      }
 256   1              ////////////////////////////////////////////
 257   1              pDirInfo=(PDIR_INFO)RspBlockOpenFile.item;
 258   1              ThisFile.StartCluster=SwapINT16(pDirInfo->startCluster);
 259   1              ThisFile.LengthInByte=SwapINT32(pDirInfo->length);
 260   1              ThisFile.ClusterPointer=ThisFile.StartCluster;
 261   1              ThisFile.SectorPointer=FirstSectorofCluster(ThisFile.StartCluster);
 262   1              ThisFile.OffsetofSector=0;
 263   1              ThisFile.SectorofCluster=0;
 264   1              //=ThisFatSecNum(clusterNum);
 265   1              //xxgFatEntOffset=ThisFatEntOffset(clusterNum);
 266   1              ThisFile.FatSectorPointer=0;
 267   1              //ThisFile.bFileOpen=1;
 268   1              ThisFile.pointer=0;
 269   1              ///////////////////////////////////////////
 270   1              FreeFat.SectorNum=DeviceInfo.FatStartSector;
 271   1              FreeFat.OldSectorNum=DeviceInfo.FatStartSector;
 272   1              FreeFat.OffsetofSector=2;
 273   1              
 274   1              return TRUE;
 275   1      #undef RspBlockOpenFile
 276   1      }
 277          
 278          unsigned char ReadFile(unsigned int readLength,unsigned char *pBuffer)
 279          {
 280   1      #define RspBlockReadFile UartRspBlock.RspBlock.Rsp_ReadFile
 281   1              unsigned int idata len,i;
 282   1              unsigned char bSuccess;
 283   1              //unsigned char sector;
 284   1              //unsigned long lba;
 285   1              
 286   1              if(!bXXGFlags.bits.SLAVE_IS_ATTACHED)
 287   1              {
 288   2              UartRspBlock.errcode=ERC_NODEVICE;
 289   2              return FALSE;           
 290   2              }
 291   1              if(!ThisFile.bFileOpen)
 292   1              {
 293   2              UartRspBlock.errcode=ERC_FILENOTOPENED;
 294   2              return FALSE;           
 295   2              }
 296   1              ///////////////////////////////////////////////////////////
 297   1              ThisFile.bFileOpen=0;
 298   1              bSuccess=1;
 299   1              UartRspBlock.len=0;
 300   1              //lba=GetSecNumFromPointer();
 301   1              //cluster=GetClusterNumFromSectorNum(lba);
 302   1              //cluster=ThisFile.StartCluster;
 303   1              //lba=FirstSectorofCluster(ThisFile.StartCluster);
C51 COMPILER V6.21  HPI                                                                    06/13/2005 16:14:56 PAGE 6   

 304   1              //readLength=SwapINT16(UartCmdBlock.CmdBlock.Cmd_ReadFile.readLength);
 305   1              if(readLength>MAX_READ_LENGTH)
 306   1                      {
 307   2                      UartRspBlock.errcode=ERC_LENGTHEXCEED;
 308   2                      return FALSE;   
 309   2                      }
 310   1              if(readLength+ThisFile.pointer>ThisFile.LengthInByte)
 311   1                      {
 312   2                      UartRspBlock.errcode=ERC_LENGTHEXCEED;
 313   2                      return FALSE;   
 314   2                      }
 315   1              ////////////////////////////////////////////
 316   1                      
 317   1                      ///////////////////////////////////////////////////
 318   1                      while(readLength>0)
 319   1                      {
 320   2                         if(readLength+ThisFile.OffsetofSector>DeviceInfo.BPB_BytesPerSec)
 321   2                              len=DeviceInfo.BPB_BytesPerSec;
 322   2                         else
 323   2                              len=readLength+ThisFile.OffsetofSector;
 324   2                         
 325   2                         //////////////////////////////////////////////////////
 326   2                         if(ThisFile.OffsetofSector>0)
 327   2                              {
 328   3                              if(RBC_Read(ThisFile.SectorPointer,1,DBUF))
 329   3                                      {
 330   4                                      //ThisFile.OffsetofSector=len;
 331   4                                      len=len-ThisFile.OffsetofSector;
 332   4                                      for(i=0;i<len;i++)
 333   4                                              //UARTBUF[i]=DBUF[ThisFile.OffsetofSector+i];
 334   4                                              *(pBuffer+i)=DBUF[ThisFile.OffsetofSector+i];
 335   4                                      ThisFile.OffsetofSector=ThisFile.OffsetofSector+len;
 336   4                                      }
 337   3                              else
 338   3                                      {
 339   4                                      UartRspBlock.errcode=ERC_DEVICEERR;
 340   4                                      return FALSE;   
 341   4                                      }
 342   3                              }
 343   2                         else
 344   2                              {
 345   3                                      if(!RBC_Read(ThisFile.SectorPointer,1,pBuffer+UartRspBlock.len))
 346   3                                      {
 347   4                                      UartRspBlock.errcode=ERC_DEVICEERR;
 348   4                                      return FALSE;   
 349   4                                      }
 350   3                                      ThisFile.OffsetofSector=len;
 351   3                              }
 352   2                         ////////////////////////////////////////////////////////////
 353   2                        // if(ThisFile.OffsetofSector>DeviceInfo.BPB_BytesPerSec-1)
 354   2                        //    ThisFile.OffsetofSector-=DeviceInfo.BPB_BytesPerSec;
 355   2                         readLength-=len;
 356   2                         UartRspBlock.len+=len;
 357   2                        // ThisFile.OffsetofSector=;
 358   2                         /////////////////////////////////////////////////////////
 359   2                         if(ThisFile.OffsetofSector>DeviceInfo.BPB_BytesPerSec-1)
 360   2                         {    
 361   3                              ThisFile.OffsetofSector-=DeviceInfo.BPB_BytesPerSec;
 362   3                              ThisFile.SectorofCluster+=1;
 363   3                              if(ThisFile.SectorofCluster>DeviceInfo.BPB_SecPerClus-1)
 364   3                              {
 365   4                                      ThisFile.SectorofCluster=0;
C51 COMPILER V6.21  HPI                                                                    06/13/2005 16:14:56 PAGE 7   

 366   4                                       ThisFile.ClusterPointer=GetNextClusterNum(ThisFile.ClusterPointer);
 367   4                                       if(ThisFile.ClusterPointer>0xffef)
 368   4                                              {
 369   5                                                 //RspBlockReadFile.errcode=ERC_REACHEND;
 370   5                                                 //RspBlockReadFile.result=0x0;
 371   5                                                 UartRspBlock.errcode=ERC_REACHEND;
 372   5                                                 return FALSE;        
 373   5                                              }
 374   4                                       ThisFile.SectorPointer=FirstSectorofCluster(ThisFile.ClusterPointer);  
 375   4                              }
 376   3                              else
 377   3                                      ThisFile.SectorPointer=ThisFile.SectorPointer+1;
 378   3                          }
 379   2                         //////////////////////////////////////////////////////////////////
 380   2                      }//end while
 381   1              
 382   1              
 383   1              ThisFile.bFileOpen=1;
 384   1              ThisFile.pointer+=UartRspBlock.len;
 385   1              //////////////////////////////////////////////
 386   1              RspBlockReadFile.readLength=SwapINT16(UartRspBlock.len);
 387   1              return TRUE;
 388   1      #undef RspBlockReadFile
 389   1      }
 390          
 391          unsigned char CreateFile(unsigned char *pBuffer)
 392          {
 393   1      #define RspBlockCreateFile UartRspBlock.RspBlock.Rsp_CreateFile
 394   1              //unsigned long sectorNum;
 395   1              unsigned int sector,i,j;
 396   1              unsigned char bstop;
 397   1              PDIR_INFO pDirInfo;
 398   1              
 399   1              if(!bXXGFlags.bits.SLAVE_IS_ATTACHED)
 400   1              {
 401   2              UartRspBlock.errcode=ERC_NODEVICE;
 402   2              return FALSE;           
 403   2              }
 404   1              ///////////////////////////////////////////////////////////
 405   1              //RspBlockCreateFile.result=0x1;
 406   1              //RspBlockCreateFile.errcode=ERC_OK;
 407   1              pDirInfo=(PDIR_INFO)pBuffer;
 408   1              ///////// Search the file of the same name  ///////////
 409   1              //UartCmdBlock.CmdBlock.Cmd_CreateFile.filename[j]
 410   1              //if(!SPC_TestUnit())
 411   1              //      return FALSE;
 412   1              //if(!RBC_Read(1,1,DBUF))
 413   1              //      return FALSE;
 414   1              //if(!RBC_Write(1,1,DBUF))
 415   1              //      return FALSE;
 416   1              //////// Search the fat for a free cluster  ////////////
 417   1              pDirInfo->startCluster=SwapINT16(GetFreeCusterNum());
 418   1              
 419   1              if(pDirInfo->startCluster<0x2)
 420   1              {
 421   2              UartRspBlock.errcode=ERC_NODEVICE;
 422   2              return FALSE;           
 423   2              }
 424   1              pDirInfo->length=0;
 425   1              /////// Search a free space in the root dir space and build the item ///
 426   1              ThisFile.bFileOpen=0;
 427   1              bstop=0;
C51 COMPILER V6.21  HPI                                                                    06/13/2005 16:14:56 PAGE 8   

 428   1              for(sector=0;sector<DeviceInfo.BPB_RootEntCnt;sector++)
 429   1                  {   
 430   2                      //////////////////////////////////////////////////
 431   2                      if(!RBC_Read(DeviceInfo.RootStartSector+sector,1,DBUF))

⌨️ 快捷键说明

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