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

📄 hpi.lst

📁 基于C51及SL811读写U盘的源程序
💻 LST
📖 第 1 页 / 共 5 页
字号:
 208   7                                                              if(base<=224)
 209   7                                                              {
 210   8                                                                      Ncount=0;
 211   8                                                                      for(k=1;k<11;k++)
 212   8                                                                      {
 213   9                                                                              ShowFileName[Lcount].LongName[base+Ncount]=DBUF[i+k];
 214   9                                                                              Ncount++;
 215   9                                                                      }
 216   8                                                                      for(k=14;k<26;k++)
 217   8                                                                      {
 218   9                                                                              ShowFileName[Lcount].LongName[base+Ncount]=DBUF[i+k];
 219   9                                                                              Ncount++;
 220   9                                                                      }
 221   8                                                                      for(k=28;k<32;k++)
 222   8                                                                      {
 223   9                                                                              ShowFileName[Lcount].LongName[base+Ncount]=DBUF[i+k];
 224   9                                                                              Ncount++;
 225   9                                                                      }
 226   8                                                              }
 227   7                                                      }
 228   6                                                      else
 229   6                                                      {
 230   7                                                              for(k=0;k<32;k++)
 231   7                                                                      ShowFileName[Lcount].item[k]=DBUF[i+k];
 232   7                                                         Lcount++;                                                    
 233   7                                                      }                       
 234   6                                      /////////////////////////////////
 235   6                                              }
 236   5                                      }
 237   4                                      if(bstop==1)break;              
 238   4                      }
 239   3      
 240   3                              if(bstop==1)break;
 241   3              
C51 COMPILER V7.07   HPI                                                                   07/13/2007 21:38:25 PAGE 5   

 242   3                              NowCluster=GetNextClusterNum(NowCluster); 
 243   3                              
 244   3                      }while(NowCluster<=0xffef);
 245   2      
 246   2              Response.len=item*32;
 247   2              return TRUE;
 248   2              }
 249   1      }
 250          
 251          unsigned char OpenFile(unsigned char *pBuffer)
 252          {
 253   1              unsigned int i;
 254   1              unsigned char j,bstop,sector;
 255   1                      
 256   1              if(!bFlags.bits.SLAVE_IS_ATTACHED)
 257   1                      return FALSE;                   
 258   1              ThisFile.bFileOpen=0;
 259   1      
 260   1              if(DirStartCluster==0)  //Root Dir
 261   1              {
 262   2              for(sector=0;sector<DeviceInfo.BPB_RootEntCnt;sector++)
 263   2                  {   
 264   3                      if(!RBC_Read(DeviceInfo.RootStartSector+sector,1,DBUF))
 265   3                              return FALSE;
 266   3                      for(i=0;i<DeviceInfo.BPB_BytesPerSec;i=i+32)
 267   3                              {
 268   4                              if(DBUF[i]==0x00)
 269   4                                      return FALSE;
 270   4                              j=0;
 271   4                              while(DBUF[i+j]==*(pBuffer+j))
 272   4                                      {
 273   5                                       j=j+1;
 274   5                                       if(j>10)
 275   5                                              break;
 276   5                                      }
 277   4                              
 278   4                              if(j>10&&(DBUF[i+11]&0x10)!=0x10)
 279   4                                  {
 280   5                                  for(j=0;j<32;j++)
 281   5                                      UARTBUF[j]=DBUF[i+j];               
 282   5                                  bstop=1;
 283   5                                  break;}
 284   4                              
 285   4                              }
 286   3                      if(bstop==1)break;
 287   3                      }
 288   2                  
 289   2                  if(sector>=DeviceInfo.BPB_RootEntCnt)
 290   2                      return FALSE;   
 291   2              }
 292   1      ///////////////////////////////////////////////////////////////////////////////////////
 293   1              else
 294   1              {
 295   2                      NowCluster=DirStartCluster;             
 296   2                      do
 297   2                      {
 298   3                              NowSector=FirstSectorofCluster(NowCluster);
 299   3                              for(sector=0;sector<DeviceInfo.BPB_SecPerClus;sector++)
 300   3                      {   
 301   4                                      if(!RBC_Read(NowSector+sector,1,DBUF))
 302   4                                              return FALSE;                           
 303   4                                      for(i=0;i<DeviceInfo.BPB_BytesPerSec;i=i+32)
C51 COMPILER V7.07   HPI                                                                   07/13/2007 21:38:25 PAGE 6   

 304   4                                      {
 305   5                                              if(DBUF[i]==0x00)
 306   5                                                      return FALSE;
 307   5                                              j=0;
 308   5                                              while(DBUF[i+j]==*(pBuffer+j))
 309   5                                              {
 310   6                                                       j=j+1;
 311   6                                                       if(j>10)
 312   6                                                              break;
 313   6                                              }
 314   5                                              if(j>10&&(DBUF[i+11]&0x10)!=0x10)
 315   5                                              { 
 316   6                                                      for(j=0;j<32;j++)
 317   6                                                      UARTBUF[j]=DBUF[i+j];                       
 318   6                                              bstop=1;
 319   6                                              break;
 320   6                                                      }
 321   5                                      }
 322   4                                      if(bstop==1)break;              
 323   4                      }
 324   3                              if(bstop==1)break;      
 325   3                              NowCluster=GetNextClusterNum(NowCluster);                       
 326   3                      }while(NowCluster<=0xffef);
 327   2                      
 328   2                      if(NowCluster>0xffef)
 329   2                      return FALSE;
 330   2              }
 331   1      
 332   1              ThisFile.bFileOpen=1;
 333   1              ThisFile.StartCluster=LSwapINT16(UARTBUF[26],UARTBUF[27]);
 334   1              ThisFile.LengthInByte=LSwapINT32(UARTBUF[28],UARTBUF[29],UARTBUF[30],UARTBUF[31]);
 335   1              ThisFile.ClusterPointer=ThisFile.StartCluster;  
 336   1              ThisFile.SectorPointer=FirstSectorofCluster(ThisFile.StartCluster);
 337   1              ThisFile.OffsetofSector=0;
 338   1              ThisFile.SectorofCluster=0;     
 339   1              ThisFile.FatSectorPointer=0;    
 340   1              ThisFile.pointer=0;
 341   1              
 342   1              Response.len=32;
 343   1              return TRUE;    
 344   1      }
 345          
 346          unsigned char ReadFile(unsigned long readLength,unsigned char *pBuffer)
 347          {
 348   1      
 349   1              unsigned int len,i;
 350   1              unsigned int tlen;      
 351   1              unsigned long blen;
 352   1      
 353   1              if(!bFlags.bits.SLAVE_IS_ATTACHED)
 354   1                      return FALSE;           
 355   1              if(!ThisFile.bFileOpen)
 356   1                      return FALSE;
 357   1      
 358   1              blen=readLength;
 359   1      
 360   1              tlen=0;
 361   1              if(readLength>MAX_READ_LENGTH)
 362   1                      return FALSE;   
 363   1              
 364   1              if(readLength+ThisFile.pointer>ThisFile.LengthInByte)
 365   1                      return FALSE;   
C51 COMPILER V7.07   HPI                                                                   07/13/2007 21:38:25 PAGE 7   

 366   1                      
 367   1              ////////////////////////////////////////////            
 368   1                      while(readLength>0)
 369   1                      {
 370   2                         if(readLength+ThisFile.OffsetofSector>DeviceInfo.BPB_BytesPerSec)
 371   2                              len=DeviceInfo.BPB_BytesPerSec;
 372   2                         else
 373   2                              len=readLength+ThisFile.OffsetofSector;
 374   2                         
 375   2                         //////////////////////////////////////////////////////
 376   2                         if(ThisFile.OffsetofSector>0)
 377   2                              {
 378   3                              if(RBC_Read(ThisFile.SectorPointer,1,DBUF))
 379   3                                      {
 380   4                                      
 381   4                                      len=len-ThisFile.OffsetofSector;
 382   4                                      for(i=0;i<len;i++)
 383   4                                              
 384   4                                              *(pBuffer+i)=DBUF[ThisFile.OffsetofSector+i];
 385   4                                      ThisFile.OffsetofSector=ThisFile.OffsetofSector+len;
 386   4                                      }
 387   3                              else
 388   3                                      return FALSE;                           
 389   3                              }
 390   2                         else
 391   2                              {
 392   3                                      if(!RBC_Read(ThisFile.SectorPointer,1,pBuffer+tlen))
 393   3                                                      return FALSE;   
 394   3                                      ThisFile.OffsetofSector=len;
 395   3                              }
 396   2                         ////////////////////////////////////////////////////////////
 397   2                         readLength-=len;
 398   2                         tlen+=len;
 399   2                        
 400   2                         /////////////////////////////////////////////////////////
 401   2                         if((ThisFile.OffsetofSector>DeviceInfo.BPB_BytesPerSec-1)&&(tlen+ThisFile.pointer<ThisFile.LengthInBy
             -te))
 402   2                         {    
 403   3                              ThisFile.OffsetofSector-=DeviceInfo.BPB_BytesPerSec;
 404   3                              ThisFile.SectorofCluster+=1;
 405   3                              if(ThisFile.SectorofCluster>DeviceInfo.BPB_SecPerClus-1)
 406   3                              {
 407   4                                      ThisFile.SectorofCluster=0;
 408   4                                       ThisFile.ClusterPointer=GetNextClusterNum(ThisFile.ClusterPointer);
 409   4                                       if(ThisFile.ClusterPointer>0xffef)
 410   4                                                 return FALSE;                                                
 411   4                                       ThisFile.SectorPointer=FirstSectorofCluster(ThisFile.ClusterPointer);  
 412   4                              }
 413   3                              else
 414   3                                      ThisFile.SectorPointer=ThisFile.SectorPointer+1;
 415   3                          }
 416   2                         //////////////////////////////////////////////////////////////////
 417   2                      }//end while
 418   1                      
 419   1              ThisFile.bFileOpen=1;
 420   1              ThisFile.pointer+=tlen;
 421   1              //////////////////////////////////////////////
 422   1              Response.len=blen;

⌨️ 快捷键说明

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