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

📄 u_func_a.lst

📁 c8051f020+CH375读写U盘文件的程序
💻 LST
📖 第 1 页 / 共 4 页
字号:
 500   3                Fat[Currt_File].Ofst=St_Ofst_a;             //文件目录项所在的偏移量
 501   3                if(*(pt+St_Ofst_a+6)==0x7e||*(pt+St_Ofst_a+5)==0x7e)
 502   3                 for(i=0;i<8;i++)
 503   3                   {            
 504   4                           if(*(pt+St_Ofst_a+i)>0x7e)
 505   4                                {
 506   5                                         rd_short=1;
 507   5                                         break;
 508   5                                         }
 509   4                               else rd_short=0;                 
 510   4                       }
 511   3                else rd_short=1; 
 512   3                 if(rd_short)    //是否为短文件名或是中文名
 513   3                    {
 514   4                         na=Fat[Currt_File].name;
 515   4                         for(j=0;j<8;j++)
 516   4                            *(na+j)=*(pt+St_Ofst_a+j);
 517   4                         *(na+8)=0;
 518   4                        }
 519   3                 else                    //若是长文件名
 520   3                  Get_Lfat_a();
 521   3                 Currt_File++;
 522   3      //         if(Currt_File==4) return  Currt_File;                
 523   3                }
 524   2              St_Ofst_a+=32;
 525   2              
 526   2              if(St_Ofst_a==512)
 527   2                {
 528   3                      St_Ofst_a=0;
 529   3                  Rd_Rec.Currt_Sect++;
 530   3                      Rd_Rec.Last_Sect=Rd_Rec.Currt_Sect-1;
 531   3                      Rd_Rec.Next_Sect=Rd_Rec.Currt_Sect+1;
 532   3                      Sect_Ofst_a++;
 533   3      //         return Currt_File; //
 534   3                 }    
 535   2              if(*(pt+St_Ofst_a)==0) 
 536   2                {
 537   3                 St_Ofst_a=0;
 538   3                 return 0xff; //文件名已读完,返回0xff
 539   3                }
 540   2         }
 541   1       return Currt_File;
C51 COMPILER V8.02   U_FUNC_A                                                              07/21/2008 09:40:01 PAGE 10  

 542   1      }                       
 543          
 544          /*******************************************************************************
 545          ------键盘处理---------------------------------------------------
 546          ********************************************************************************
 547          说明: 入口参数:无
 548                    出口参数:0
 549          *******************************************************************************/
 550          unsigned char Key_Opare_a()
 551          { 
 552   1       signed char Key,i=0,j;
 553   1      // LCD_Printf(1,1,">>");
 554   1      CurrtChainNum=0;        
 555   1       while(1)
 556   1        {
 557   2         Key=Wait_Infrared();
 558   2         switch(Key)
 559   2           {
 560   3                 case UP:     i--;break;
 561   3                 case DOWN:   i++;break; 
 562   3                 case OK:     Opr_Menu_a(i);i=0;break;
 563   3                 case CANCEL: if(CurrtChainNum==0) break;                     
 564   3                                              CurrtChainNum-=2;
 565   3                              i=0;
 566   3                                              Dis_Fat_In_Clust_a(ClustChain[CurrtChainNum]);
 567   3                                              CurrtChainNum++;
 568   3                                              break;
 569   3                 case 0x0b:   return 0;       //系统重新开始
 570   3               }
 571   2               if(i>=Currt_File) i=Currt_File-1;
 572   2               if((i/4)==(Currt_File/4))
 573   2               {
 574   3                j=1;
 575   3                LCD_Clear ();
 576   3                while((j+(i/4)*4)<=Currt_File)
 577   3                  {
 578   4                       PrintfFat(j,2,(j-1)+(i/4)*4);
 579   4                       j++;
 580   4                      }
 581   3               }
 582   2               else
 583   2               {
 584   3      //        LCD_Clear ();
 585   3                      for(j=1;j<=4;j++)
 586   3                        PrintfFat(j,2,(j-1)+(i/4)*4);
 587   3                }
 588   2         switch(i%4)
 589   2           {
 590   3            case -1:    i=0;break;
 591   3      //        case 4:         return 0x00;
 592   3                case 0:     LCD_Printf(1,1,">>");
 593   3                            LCD_Printf(2,1,"  ");
 594   3                                        LCD_Printf(3,1,"  ");
 595   3                                        LCD_Printf(4,1,"  ");
 596   3                                        break; 
 597   3                case 1:     LCD_Printf(2,1,">>");
 598   3                            LCD_Printf(1,1,"  ");
 599   3                                        LCD_Printf(3,1,"  ");
 600   3                                        LCD_Printf(4,1,"  ");
 601   3                                        break; 
 602   3                case 2:     LCD_Printf(3,1,">>");
 603   3                            LCD_Printf(2,1,"  ");
C51 COMPILER V8.02   U_FUNC_A                                                              07/21/2008 09:40:01 PAGE 11  

 604   3                                        LCD_Printf(1,1,"  ");
 605   3                                        LCD_Printf(4,1,"  ");
 606   3                                        break; 
 607   3                case 3:     LCD_Printf(4,1,">>");
 608   3                            LCD_Printf(2,1,"  ");
 609   3                                        LCD_Printf(3,1,"  ");
 610   3                                        LCD_Printf(1,1,"  ");
 611   3                                        break; 
 612   3           }
 613   2         }
 614   1      }
 615          
 616          
 617          /*******************************************************************************
 618          ------文件处理程序---------------------------------------------------
 619          ********************************************************************************
 620          说明: 若为文件夹,则打开,若为文件,则询问是否传输
 621                入口参数:文件号
 622                    出口参数:无
 623          *******************************************************************************/
 624          void Opr_Menu_a(unsigned char file_num)
 625          {
 626   1       unsigned char *pt,Remain;
 627   1       unsigned long FirstClustB;
 628   1       pt=Fat[file_num].ext;
 629   1       if(CurrtChainNum==0)
 630   1         {
 631   2              ClustChain[CurrtChainNum]=2;
 632   2          CurrtChainNum=1;
 633   2         }
 634   1       if(*(pt)==0x20)
 635   1         {
 636   2          ClustChain[CurrtChainNum]=Fat[file_num].St_Clust.value;
 637   2          CurrtChainNum++;
 638   2              Dis_Fat_In_Clust_a(Fat[file_num].St_Clust.value);
 639   2         }
 640   1       else
 641   1         {
 642   2          LCD_Clear ();
 643   2          LCD_Printf(2,2,"发送到另一盘?");
 644   2              if(Wait_Infrared()==OK)
 645   2                 {
 646   3                  LCD_Clear ();
 647   3              LCD_Printf(2,2,"正在发送...");
 648   3                  FirstClustB=WrFAT_b(file_num);
 649   3                      do{
 650   4                         Remain=ReadAA(file_num);
 651   4                         Remain=WriteAB(FirstClustB,file_num);
 652   4                    }while(Remain==0xff);
 653   3      
 654   3                      RdFDT_a(file_num);
 655   3                      WrFDT_b(FirstClustB);
 656   3                      Rd_Sector_b(root_b);
 657   3                 }
 658   2              else return;
 659   2         }
 660   1      }
 661          
 662          /*******************************************************************************
 663          ------读A盘FDT---------------------------------------------------
 664          ********************************************************************************
 665          说明: 存入FDTBuf
C51 COMPILER V8.02   U_FUNC_A                                                              07/21/2008 09:40:01 PAGE 12  

 666                入口参数:文件号
 667                    出口参数:无
 668          *******************************************************************************/
 669          void RdFDT_a(unsigned char file_num)
 670          {
 671   1       unsigned char xdata *pt;
 672   1       unsigned char i,j=0,LFile=0;
 673   1       unsigned int temp_ofst;
 674   1       pt=Data_Buf;
*** WARNING C182 IN LINE 674 OF U_FUNC_A.C: pointer to different objects
 675   1       Rd_Sector_a(Fat[file_num].Sector);
 676   1       temp_ofst=Fat[file_num].Ofst;
 677   1       for(i=0;i<32;i++)
 678   1         {
 679   2          FDTBuf.Buf[i]=*(pt+temp_ofst+i);
 680   2              FDTBuf.FDTNum=32;
 681   2              
 682   2              if(*(pt+temp_ofst+i)>=0x7e&&i<8)        //判断是否是长文件名
 683   2                 LFile=1;
 684   2              
 685   2         }
 686   1         j=1;
 687   1       if(LFile==0) return;
 688   1         
 689   1       do
 690   1         {
 691   2          if(temp_ofst==0)
 692   2                 {
 693   3                  Rd_Sector_a(Fat[file_num].Sector-1);
 694   3                      temp_ofst=512;
 695   3                      }
 696   2               temp_ofst-=32;
 697   2               for(i=0;i<32;i++)
 698   2                 {
 699   3                  FDTBuf.Buf[32*j+i]=*(pt+temp_ofst+i);
 700   3                 }
 701   2               FDTBuf.FDTNum+=32;
 702   2               j++;
 703   2         }while(*(pt+temp_ofst)<0x40);
 704   1      
 705   1      }
 706          
 707          /*******************************************************************************
 708          ------写B盘FDT---------------------------------------------------
 709          ********************************************************************************
 710          说明: 入口参数:文件号
 711                    出口参数:无
 712          *******************************************************************************/
 713          void WrFDT_b(unsigned long FirstClust)
 714          {
 715   1       unsigned char i,j,CtnsNum=0,SectOfst;
 716   1       unsigned char xdata *pt;
 717   1       unsigned int temp_ofst;
 718   1       pt=Data_Buf;
*** WARNING C182 IN LINE 718 OF U_FUNC_A.C: pointer to different objects
 719   1       FDTBuf.Buf[0x1a]=(unsigned char)FirstClust;             //修改首簇号
 720   1       FDTBuf.Buf[0x1b]=(unsigned char)(FirstClust>>8);
 721   1       FDTBuf.Buf[0x14]=(unsigned char)(FirstClust>>16);
 722   1       FDTBuf.Buf[0x15]=(unsigned char)(FirstClust>>24);
 723   1       for(i=0;i<sect_clust_b;i++)
 724   1        {
 725   2         Rd_Sector_b(root_b+i);
C51 COMPILER V8.02   U_FUNC_A                                                              07/21/2008 09:40:01 PAGE 13  

 726   2         temp_ofst=0;
 727   2         for(j=0;j<16;j++)
 728   2            {
 729   3                 if(*(pt+j*32)==0||*(pt+j*32)==0xe5)
 730   3                    CtnsNum++;
 731   3                 else CtnsNum=0;
 732   3                 if(CtnsNum*32==FDTBuf.FDTNum)   //如果找到足够的FDT
 733   3                    {
 734   4                         temp_ofst=j*32;
 735   4                         break;
 736   4                        }
 737   3                }
 738   2         if(j<16)                //如果是因为找到足够的FDT而跳出上一个循环
 739   2               {
 740   3                SectOfst=i;
 741   3            break;
 742   3               }
 743   2        }
 744   1        if(i==sect_clust_b) return;   //如果没找到空FDT
 745   1       for(i=0;i<CtnsNum;i++)
 746   1          {
 747   2               for(j=0;j<32;j++)
 748   2                   {
 749   3                        *(pt+temp_ofst+j)=FDTBuf.Buf[32*i+j];
 750   3                       }
 751   2           if(temp_ofst==0)
 752   2                   {
 753   3                        Wr_Sector_b(root_b+SectOfst);
 754   3                        SectOfst--;
 755   3                        Rd_Sector_b(root_b+SectOfst);
 756   3                        temp_ofst=480;

⌨️ 快捷键说明

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