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

📄 hpi.lst

📁 采用811芯片实现单片机读写U盘的源代码
💻 LST
📖 第 1 页 / 共 4 页
字号:
 238   4                                      if(!CreateClusterLink(clus_temp)) return DEVICEC_OP_ERR;
 239   4                                      if(!updata_fat_free()) return DEVICEC_OP_ERR;
 240   4                              }       
C51 COMPILER V7.00  HPI                                                                    09/22/2005 17:15:31 PAGE 5   

 241   3                      }else{
 242   3                              if(sector_temp==end_sector) break;
 243   3                      }       
 244   2              }       
 245   1              
 246   1              if(!bstop) return DEVICE_FULL;
 247   1              if(!RBC_Write(start_sec,1,DBUF)) return DEVICEC_OP_ERR;
 248   1              return 0;       
 249   1      }
 250          
 251          /********************************************************
 252          读取当前目录下的文件列表
 253          说明:每个文件项中的数据均为小端模式(即PC模式)
 254          ********************************************************/       
 255          uchar List(uchar *para)
 256          {
 257   1              uint item,i;
 258   1              uchar bstop,end_sector;
 259   1              uchar error,package=1;
 260   1              uchar sector_temp;
 261   1              ulong start_sec,clus_temp;
 262   1              
 263   1              if(!bXXGFlags.bits.SLAVE_IS_ATTACHED)
 264   1              {
 265   2                      return NOT_DEVICE;              
 266   2              }
 267   1              
 268   1              item=0;bstop=0;
 269   1              start_sec=cur_dir_info.start_sec;
 270   1              clus_temp=cur_dir_info.start_clue;
 271   1              end_sector=(uchar)(deviceinfo.RootEntCnt>>4);
 272   1              
 273   1              sector_temp=0;
 274   1              while(1){
 275   2                      
 276   2                      if(!RBC_Read(start_sec,1,DBUF))
 277   2                              return NOT_DEVICE;
 278   2                              
 279   2                      for(i=0;i<deviceinfo.BytePerSec;i+=32){
 280   3                              if(DBUF[i]==0x00){
 281   4                                      bstop=1;
 282   4                                      break;
 283   4                              }
 284   3                              if((DBUF[i]==0xE5)||(DBUF[i+11]==0x0f))
 285   3                                      continue;
 286   3                              else{
 287   4                                      if(DBUF[i]==0x05) DBUF[i]=0xe5;
 288   4                                      if(item>1023){
 289   5                                              error=send_data(package,item,para);
 290   5                                              if(error) return error;
 291   5                                              package++;
 292   5                                              item=0;
 293   5                                      }
 294   4                                      memcpy_cur(&para[item], &DBUF[i], 32);
 295   4                                      item=item+32;
 296   4                              }
 297   3                      }
 298   2                      
 299   2                      if(bstop==1)break;
 300   2                      start_sec++;
 301   2                      sector_temp++;
 302   2                      if((deviceinfo.type)||(!cur_dir_info.root_flag)){
C51 COMPILER V7.00  HPI                                                                    09/22/2005 17:15:31 PAGE 6   

 303   3                              if(sector_temp==deviceinfo.SecPerClus){
 304   4                                      clus_temp=GetNextClusterNum(clus_temp);
 305   4                                      if((clus_temp>0x0fffffef)||(!clus_temp)) break;
 306   4                                      start_sec=FirstSectorofCluster(clus_temp);
 307   4                              }       
 308   3                      }else{
 309   3                              if(sector_temp==end_sector) break;
 310   3                      }       
 311   2              }       
 312   1                      
 313   1              if(item){
 314   2                      error=send_data(0,item,para);
 315   2                      if(error) return error; 
 316   2              }       
 317   1              
 318   1              return 0;
 319   1      
 320   1      }
 321          
 322          /********************************************************
 323          打开文件
 324          说明:参数包括11个字节文件名(ASC),4个字节当前日期(HEX),3个字节当前时间(HEX)
 325                该函数仅在当前目录中查找,若打开的为目录,则进入该目录
 326          ********************************************************/      
 327          uchar OpenFile(uint len,uchar *para)
 328          {
 329   1      
 330   1              uchar error;
 331   1              ulong clus_temp;
 332   1              uchar up_dir[11]={0x2e,0x2e,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20};
 333   1              uchar my_dir[11]={0x2e,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20};
 334   1              
 335   1      //      PDIR_INFO xdata pDirInfo;
 336   1              
 337   1              if(!bXXGFlags.bits.SLAVE_IS_ATTACHED)
 338   1              {
 339   2                      return NOT_DEVICE;              
 340   2              }
 341   1              
 342   1              if(len!=18) return RECE_DATA_ERR;
 343   1      
 344   1              memcpy_cur(file_point.name, para,11);
 345   1                              
 346   1              file_point.file_open_flag=0;
 347   1      //      end_sector=(uchar)(DeviceInfo.BPB_RootEntCnt>>4);
 348   1              
 349   1              #ifdef ZLH_DEBUG
 350   1      //      disp_data(2,"A2");
 351   1      //      disp_data(4,&DeviceInfo.StartSector);
 352   1      //      disp_data(4,&DeviceInfo.RootStartSector);
 353   1      //      disp_data(2,&DeviceInfo.BPB_RootEntCnt);
 354   1      //      disp_data(2,&end_sector);
 355   1      //      disp_data(11,pBuffer);
 356   1      //      while(!getkey());
 357   1              #endif
 358   1              
 359   1              error=find_file(file_point.name,(uchar *)&cur_file_item,0);
 360   1              if(error) return error;
 361   1              
 362   1              clus_temp=((ulong)cur_file_item.dir_fstcluslo)<<16+cur_file_item.dir_fstclushi;
 363   1              clus_temp=SwapINT32(clus_temp);
 364   1              
C51 COMPILER V7.00  HPI                                                                    09/22/2005 17:15:31 PAGE 7   

 365   1              if(cur_file_item.dir_attr&0x10){  //打开目录
 366   2                      if(memcmp_cur(file_point.name,my_dir,11)==0){
 367   3                               //选择本目录
 368   3                              send_data(0,0,para);
 369   3                              return 0;
 370   3                      }
 371   2      
 372   2                      if(memcmp_cur(file_point.name,up_dir,11)==0){
 373   3                              if(!clus_temp){
 374   4                                       //上级目录为根目录
 375   4                                      cur_dir_info.root_flag=1;
 376   4                                      cur_dir_info.start_sec=deviceinfo.RootFirstSec;
 377   4                                      if(deviceinfo.type){
 378   5                                              cur_dir_info.start_clue=2;
 379   5                                              cur_dir_info.fat_sec=deviceinfo.FATFirstSec;
 380   5                                      }       
 381   4                                      else{
 382   5                                              cur_dir_info.start_clue=0;
 383   5                                              cur_dir_info.fat_sec=0;
 384   5                                      }
 385   4                              }
 386   3                              else{           
 387   4                                      cur_dir_info.root_flag=0;
 388   4                                      cur_dir_info.start_clue=clus_temp;
 389   4                                      cur_dir_info.start_sec=FirstSectorofCluster(clus_temp);
 390   4                                      cur_dir_info.fat_sec=ThisFatSecNum(clus_temp);
 391   4                                      //打开的是目录(根目录不包括)
 392   4                                      //目录文件永远没有大小
 393   4                                      file_point.type=0;
 394   4                                      file_point.file_start_clue=cur_dir_info.start_clue;
 395   4                                      file_point.file_size=SwapINT32(cur_file_item.dir_file_size);    
 396   4                                      file_point.current_clue=file_point.file_start_clue;
 397   4                                      file_point.current_sec=cur_dir_info.start_sec;
 398   4                                      file_point.offset_sec_clue=0;
 399   4                                      file_point.offset_byte=0;
 400   4                                      file_point.offset_fat_sec=cur_dir_info.fat_sec;
 401   4                                      file_point.offset_point=0;
 402   4                                      file_point.file_open_flag=1;    
 403   4                              }
 404   3                      }       
 405   2              }
 406   1              else{
 407   2                      //打开文件
 408   2                      if(cur_file_item.dir_file_size){
 409   3                              file_point.file_start_clue=clus_temp;
 410   3                              file_point.file_size=SwapINT32(cur_file_item.dir_file_size);
 411   3                      
 412   3                              file_point.current_clue=file_point.file_start_clue;
 413   3                              file_point.current_sec=FirstSectorofCluster(file_point.current_clue);
 414   3                              file_point.offset_sec_clue=0;
 415   3                              file_point.offset_byte=0;
 416   3                              file_point.offset_fat_sec=ThisFatSecNum(file_point.current_clue);
 417   3                      }else{
 418   3                              file_point.file_size=0;
 419   3                      }               
 420   2                      file_point.offset_point=0;
 421   2                      file_point.type=1;
 422   2                      file_point.file_open_flag=1;    
 423   2              }       
 424   1              
 425   1              memcpy_cur(file_point.date,&para[11], 7);
 426   1              
C51 COMPILER V7.00  HPI                                                                    09/22/2005 17:15:31 PAGE 8   

 427   1      //      for(i=0,j=11;i<4;i++,j++)
 428   1      //              file_point.date[i]=para[j];
 429   1      //      for(i=0;i<3;i++,j++);
 430   1      //              file_point.time[i]=para[j];             
 431   1              
 432   1              #ifdef ZLH_DEBUG
 433   1              disp_data(2,"B3");
 434   1              disp_data(68,&deviceinfo);
 435   1              #endif
 436   1              
 437   1              if(file_point.type) send_data(0,32,(uchar *)&cur_file_item);
 438   1              else send_data(0,0,para);
 439   1              
 440   1              return 0;
 441   1      }
 442          
 443          /*****************************************************************
 444          读取当前文件数据
 445          *****************************************************************/
 446          uchar ReadFile(uint readLength,uchar *para)
 447          {
 448   1              uint len,position=0;
 449   1              uchar bSuccess;
 450   1              //unsigned char sector;
 451   1              //unsigned long lba;
 452   1              
 453   1              if(!bXXGFlags.bits.SLAVE_IS_ATTACHED)
 454   1              {
 455   2                      return NOT_DEVICE;              
 456   2              }
 457   1      
 458   1              if(!file_point.file_open_flag)
 459   1              {
 460   2                      return FILE_NOT_OPEN;           
 461   2              }
 462   1              
 463   1              //目录不能读
 464   1              if(!file_point.type) return FILE_NOT_OPEN;
 465   1              
 466   1              if(!file_point.file_size) return FILE_LENTH_OVER;
 467   1              
 468   1              if(!readLength) return RECE_DATA_ERR;
 469   1              
 470   1              file_point.file_open_flag=0;
 471   1                
 472   1              bSuccess=1;
 473   1              
 474   1              if(readLength+file_point.offset_point>file_point.file_size)
 475   1              {
 476   2      //              return FILE_LENTH_OVER; 
 477   2                      readLength=file_point.file_size-file_point.offset_point;
 478   2              }
 479   1              
 480   1              file_point.offset_point+=readLength;
 481   1                      
 482   1              while(readLength>0)

⌨️ 快捷键说明

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