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

📄 hpi.lst

📁 51+sl811读写U盘的源程序+原理图
💻 LST
📖 第 1 页 / 共 4 页
字号:
 203   1              //RspBlockOpenFile.errcode=ERC_OK;
 204   1              for(sector=0;sector<DeviceInfo.BPB_RootEntCnt;sector++)
 205   1                  {   
 206   2                      //////////////////////////////////////////////////
 207   2                      if(!RBC_Read(DeviceInfo.RootStartSector+sector,1,DBUF))
 208   2                              {
 209   3                              UartRspBlock.errcode=ERC_DEVICEERR;
 210   3                              return FALSE;   
 211   3                              
 212   3                              }
 213   2                      ///////////////////////////////////////////////////
 214   2                      for(i=0;i<DeviceInfo.BPB_BytesPerSec;i=i+32)
 215   2                              {
 216   3                              if(DBUF[i]==0x00)
 217   3                                      {
 218   4                                      UartRspBlock.errcode=ERC_FILENOTFOUND;
 219   4                                      //UartRspBlock.errcode=ERC_DEVICEERR;
 220   4                                      return FALSE;   
 221   4                                      }
 222   3                              ///////////////////////////////////////////
 223   3                              j=0;
 224   3                              while(DBUF[i+j]==*(pBuffer+j))
 225   3                                      {
 226   4                                       j=j+1;
 227   4                                       if(j>10)
 228   4                                              break;
 229   4                                      }
 230   3                              
 231   3                              if(j>10)
 232   3                                  {
 233   4                                  for(j=0;j<32;j++)
 234   4                                      RspBlockOpenFile.item[j]=DBUF[i+j];
 235   4                                  //RspBlockOpenFile.result=0x1;
 236   4                                  ThisFile.bFileOpen=1;
 237   4                                  bstop=1;
 238   4                                   break;}
 239   3                              
 240   3                              }
 241   2                      ///////////////////////////////////////////////////////
C51 COMPILER V7.50   HPI                                                                   11/02/2007 09:31:21 PAGE 5   

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

 304   1              if(readLength+ThisFile.pointer>ThisFile.LengthInByte)
 305   1                      {
 306   2                      UartRspBlock.errcode=ERC_LENGTHEXCEED;
 307   2                      return FALSE;   
 308   2                      }
 309   1              ////////////////////////////////////////////
 310   1                      
 311   1                      ///////////////////////////////////////////////////
 312   1                      while(readLength>0)
 313   1                      {
 314   2                         if(readLength+ThisFile.OffsetofSector>DeviceInfo.BPB_BytesPerSec)
 315   2                              len=DeviceInfo.BPB_BytesPerSec;
 316   2                         else
 317   2                              len=readLength+ThisFile.OffsetofSector;
 318   2                         
 319   2                         //////////////////////////////////////////////////////
 320   2                         if(ThisFile.OffsetofSector>0)
 321   2                              {
 322   3                              if(RBC_Read(ThisFile.SectorPointer,1,DBUF))
 323   3                                      {
 324   4                                      //ThisFile.OffsetofSector=len;
 325   4                                      len=len-ThisFile.OffsetofSector;
 326   4                                      for(i=0;i<len;i++)
 327   4                                              //UARTBUF[i]=DBUF[ThisFile.OffsetofSector+i];
 328   4                                              *(pBuffer+i)=DBUF[ThisFile.OffsetofSector+i];
 329   4                                      ThisFile.OffsetofSector=ThisFile.OffsetofSector+len;
 330   4                                      }
 331   3                              else
 332   3                                      {
 333   4                                      UartRspBlock.errcode=ERC_DEVICEERR;
 334   4                                      return FALSE;   
 335   4                                      }
 336   3                              }
 337   2                         else
 338   2                              {
 339   3                                      if(!RBC_Read(ThisFile.SectorPointer,1,pBuffer+UartRspBlock.len))
 340   3                                      {
 341   4                                      UartRspBlock.errcode=ERC_DEVICEERR;
 342   4                                      return FALSE;   
 343   4                                      }
 344   3                                      ThisFile.OffsetofSector=len;
 345   3                              }
 346   2                         ////////////////////////////////////////////////////////////
 347   2                        // if(ThisFile.OffsetofSector>DeviceInfo.BPB_BytesPerSec-1)
 348   2                        //    ThisFile.OffsetofSector-=DeviceInfo.BPB_BytesPerSec;
 349   2                         readLength-=len;
 350   2                         UartRspBlock.len+=len;
 351   2                        // ThisFile.OffsetofSector=;
 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;
C51 COMPILER V7.50   HPI                                                                   11/02/2007 09:31:21 PAGE 7   

 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              
 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)

⌨️ 快捷键说明

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