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

📄 u_func_a.lst

📁 c8051f020+CH375读写U盘文件的程序
💻 LST
📖 第 1 页 / 共 4 页
字号:
 757   3                       }
 758   2               else temp_ofst-=32;
 759   2              }
 760   1        Wr_Sector_b(root_b+SectOfst);
 761   1      }
 762          
 763          /*******************************************************************************
 764          ------写B盘FAT---------------------------------------------------
 765          ********************************************************************************
 766          说明: 入口参数:文件号
 767                    出口参数:首簇号
 768          *******************************************************************************/
 769          unsigned long WrFAT_b(unsigned char file_num)
 770          {
 771   1       unsigned char xdata *pt;
 772   1       unsigned char SectFirst,SectChange;
 773   1       UINT32 data ClustNum;
 774   1       UINT32 temp_clust;
 775   1       struct{
 776   1                  unsigned long SectOfst;
 777   1                      unsigned int ByteOfst;
 778   1             }c1,c2;
 779   1       unsigned long data i;
 780   1       unsigned char data j;
 781   1       unsigned long fat_b,ChangeClust=0,SumClust,FirstClust=0;
 782   1       pt=Data_Buf;
*** WARNING C182 IN LINE 782 OF U_FUNC_A.C: pointer to different objects
 783   1      
 784   1       SumClust=Fat[file_num].Big.value/(512*sect_clust_b)+1;
 785   1       fat_b=hidd_sect_b+resv_sect_b;
 786   1       for(i=0;i<sect_fat_b;i++)
C51 COMPILER V8.02   U_FUNC_A                                                              07/21/2008 09:40:01 PAGE 14  

 787   1          {
 788   2           Rd_Sector_b(fat_b+i);
 789   2               SectFirst=1;
 790   2               SectChange=0;
 791   2               for(j=0;j<128;j++)
 792   2                  {
 793   3                       ClustNum.num[3]=*(pt+j*4);
 794   3                       ClustNum.num[2]=*(pt+j*4+1);
 795   3                       ClustNum.num[1]=*(pt+j*4+2);
 796   3                       ClustNum.num[0]=*(pt+j*4+3);
 797   3                       if(ClustNum.value==0)           //是否为空
 798   3                          {
 799   4                               SectChange=1;
 800   4                               if(FirstClust==0)
 801   4                                 {
 802   5                                      FirstClust=j+128*i;              //首簇号
 803   5                                      c1.SectOfst=i;
 804   5                                      c1.ByteOfst=j*4;
 805   5                                      c2.SectOfst=i;
 806   5                                      c2.ByteOfst=j*4;
 807   5                                      SectFirst=0;
 808   5                                      }
 809   4                               else
 810   4                                  {
 811   5                                       c2.SectOfst=i;
 812   5                                       c2.ByteOfst=j*4;
 813   5                                       temp_clust.value=j+128*i;        //c2指向的簇号
 814   5                                       if(SectFirst==1)               //若为此扇区的第一空簇
 815   5                                          {
 816   6                                               Rd_Sector_b(fat_b+c1.SectOfst);
 817   6                                               *(pt+c1.ByteOfst)=temp_clust.num[3];
 818   6                                               *(pt+c1.ByteOfst+1)=temp_clust.num[2];
 819   6                                               *(pt+c1.ByteOfst+2)=temp_clust.num[1];
 820   6                                               *(pt+c1.ByteOfst+3)=temp_clust.num[0];
 821   6                                               Wr_Sector_b(fat_b+c1.SectOfst);
 822   6                                               Wr_Sector_b(fat_b+sect_fat_b+c1.SectOfst);     //写FAT2
 823   6                                               Rd_Sector_b(fat_b+c2.SectOfst);
 824   6                                               c1=c2;
 825   6                                               SectFirst=0;   
 826   6                                              }
 827   5                                        else
 828   5                                          {
 829   6                                               *(pt+c1.ByteOfst)=temp_clust.num[3];
 830   6                                               *(pt+c1.ByteOfst+1)=temp_clust.num[2];
 831   6                                               *(pt+c1.ByteOfst+2)=temp_clust.num[1];
 832   6                                               *(pt+c1.ByteOfst+3)=temp_clust.num[0];
 833   6                                               c1=c2;
 834   6                                              }                                       
 835   5                                       }
 836   4                              ChangeClust++;
 837   4                              if(ChangeClust>=SumClust) 
 838   4                                 {
 839   5                                  *(pt+c2.ByteOfst)=0xff;
 840   5                                  *(pt+c2.ByteOfst+1)=0xff;
 841   5                                      *(pt+c2.ByteOfst+2)=0xff;
 842   5                                      *(pt+c2.ByteOfst+3)=0x0f;
 843   5                                  break;                          
 844   5                                 }                    
 845   4                              }
 846   3                      }
 847   2                if(SectChange==1)
 848   2                    {
C51 COMPILER V8.02   U_FUNC_A                                                              07/21/2008 09:40:01 PAGE 15  

 849   3                     Wr_Sector_b(fat_b+i);//此扇区修改完毕,写入,注:最后一空簇可能未写
 850   3                     Wr_Sector_b(fat_b+sect_fat_b+c1.SectOfst);    //写FAT2
 851   3                     if(ChangeClust>=SumClust) return FirstClust;
 852   3                        }
 853   2              }
 854   1      }
 855          
 856          /*******************************************************************************
 857          ------读A盘文件的某一扇区---------------------------------------------------
 858          ********************************************************************************
 859          说明: 写入单片机中数据缓冲区
 860                入口参数:文件号
 861                    出口参数:0x00:文件结束,0xff:文件还未读完
 862          *******************************************************************************/
 863          unsigned char ReadAA(unsigned char file_num)    
 864          {
 865   1       static unsigned char data TempSectOfstAA;
 866   1       unsigned char xdata *Fpt;
 867   1       unsigned int data temp_ofst;
 868   1       static unsigned long data BaseSectAA,SumSectorAA,SectorAA=0;
 869   1       Fpt=FATBufA; 
 870   1       if(SectorAA==0)
 871   1          {
 872   2           ClusterA.NextClust.value=Fat[file_num].St_Clust.value;                
 873   2           SumSectorAA=Fat[file_num].Big.value/512+1;
 874   2              }
 875   1       if(SectorAA<=SumSectorAA)
 876   1          {
 877   2               
 878   2               if(SectorAA%sect_clust_a==0)
 879   2                  {
 880   3                       
 881   3                       if(ClusterA.NextClust.value/128!=ClusterA.CurrtClust/128||SectorAA==0)
 882   3                          {
 883   4                               ClusterA.CurrtClust=ClusterA.NextClust.value;
 884   4                               Rd_FAT_a(ClusterA.NextClust.value/128+resv_sect_a+hidd_sect_a);
 885   4                              }
 886   3                       else
 887   3                          {
 888   4                                ClusterA.CurrtClust=ClusterA.NextClust.value;
 889   4                              }
 890   3                                temp_ofst=(ClusterA.CurrtClust%128)*4;                        
 891   3                                ClusterA.NextClust.num[3]=*(Fpt+temp_ofst);
 892   3                                ClusterA.NextClust.num[2]=*(Fpt+temp_ofst+1);
 893   3                                ClusterA.NextClust.num[1]=*(Fpt+temp_ofst+2);
 894   3                                ClusterA.NextClust.num[0]=*(Fpt+temp_ofst+3);
 895   3                                BaseSectAA=(ClusterA.CurrtClust-2)*sect_clust_a+root_a;
 896   3                                TempSectOfstAA=0;                     
 897   3                      }
 898   2               Rd_Sector_a(BaseSectAA+TempSectOfstAA);                   //读一扇区
 899   2               TempSectOfstAA++;
 900   2               SectorAA++;
 901   2              }
 902   1        if(SectorAA>=SumSectorAA)
 903   1          {
 904   2               SectorAA=0;
 905   2           return 0x00;
 906   2              }
 907   1        else return 0xff;
 908   1      }
 909          
 910          
C51 COMPILER V8.02   U_FUNC_A                                                              07/21/2008 09:40:01 PAGE 16  

 911          /*******************************************************************************
 912          ------写B盘某一扇区---------------------------------------------------
 913          ********************************************************************************
 914          说明: 入口参数:首簇号,文件号
 915                    出口参数:0x00:文件写结束,0xff:文件还未写完
 916          *******************************************************************************/
 917          unsigned char WriteAB(unsigned long FirstClust,unsigned char file_num)          //AB表示A为主盘,对B操作
 918          {
 919   1       static unsigned char data TempSectOfstAB;
 920   1       unsigned char xdata *Fpt;
 921   1       unsigned int data temp_ofst;
 922   1       static unsigned long data SectorAB=0,SumSectorAB,BaseSectAB;
 923   1       Fpt=FATBufB;
 924   1       if(SectorAB==0)
 925   1           {
 926   2            ClusterB.NextClust.value=FirstClust;
 927   2            SumSectorAB=Fat[file_num].Big.value/512+1;
 928   2               }
 929   1       if(SectorAB<=SumSectorAB)
 930   1          {
 931   2               
 932   2               if(SectorAB%sect_clust_b==0)
 933   2                  {
 934   3                       
 935   3                       if(ClusterB.NextClust.value/128!=ClusterB.CurrtClust/128||SectorAB==0)
 936   3                          {
 937   4                               ClusterB.CurrtClust=ClusterB.NextClust.value;
 938   4                               Rd_FAT_b(ClusterB.NextClust.value/128+resv_sect_b+hidd_sect_b);
 939   4                              }
 940   3                       else
 941   3                          {
 942   4                                ClusterB.CurrtClust=ClusterB.NextClust.value;
 943   4                              }
 944   3                                temp_ofst=(ClusterB.CurrtClust%128)*4;                        
 945   3                                ClusterB.NextClust.num[3]=*(Fpt+temp_ofst);
 946   3                                ClusterB.NextClust.num[2]=*(Fpt+temp_ofst+1);
 947   3                                ClusterB.NextClust.num[1]=*(Fpt+temp_ofst+2);
 948   3                                ClusterB.NextClust.num[0]=*(Fpt+temp_ofst+3);
 949   3                                BaseSectAB=(ClusterB.CurrtClust-2)*sect_clust_b+root_b;
 950   3                                TempSectOfstAB=0;                     
 951   3                      }
 952   2               Wr_Sector_b(BaseSectAB+TempSectOfstAB);                   //读一扇区
 953   2               TempSectOfstAB++;
 954   2               SectorAB++;
 955   2              }
 956   1        if(SectorAB>=SumSectorAB) 
 957   1            {
 958   2                 SectorAB=0;
 959   2                 return 0x00;
 960   2                }
 961   1        else return 0xff;
 962   1      }
 963          
 964          /*******************************************************************************
 965          ------读AFAT表---------------------------------------------------
 966          ********************************************************************************
 967          说明: 入口参数:扇区号LBA
 968                    出口参数:0x14:读取成功,0x1f:读取失败
 969          *******************************************************************************/
 970          unsigned char Rd_FAT_a(unsigned long LBA)               
 971          {
 972   1        unsigned char sta,i,j,Next_Num=0;
C51 COMPILER V8.02   U_FUNC_A                                                              07/21/2008 09:40:01 PAGE 17  

 973   1        unsigned char xdata *pt;
 974   1        sta=0x1f;
 975   1        pt=FATBufA;
 976   1        CH375HM_INDEX_WR_a( DISK_READ );                        /* 从USB存储器读数据块 */
 977   1        CH375HM_DATA_WR_a( (unsigned char)LBA );                /* LBA的最低8位 */
 978   1        CH375HM_DATA_WR_a( (unsigned char)( LBA >> 8 ) );
 979   1        CH375HM_DATA_WR_a( (unsigned char)( LBA >> 16 ) );
 980   1        CH375HM_DATA_WR_a( (unsigned char)( LBA >> 24 ) );      /* LBA的最高8位 */
 981   1        CH375HM_DATA_WR_a( 1 );                           /* 扇区数 */ 
 982   1        Delay();
 983   1        for(i=0;i<9;i++)
 984   1          {
 985   2              sta=Wait_Int_a();
 986   2           if(sta==0x1f||sta==0x14) return sta;
 987   2               CH375HM_INDEX_WR_a(RD_USB_DATA);
 988   2               Next_Num=CH375HM_DATA_RD_a();
 989   2           for(j=0;j<Next_Num;j++)
 990   2                  {
 991   3                       *pt=CH375HM_DATA_RD_a();
 992   3                       pt++;
 993   3                      }
 994   2                CH375HM_INDEX_WR_a(DISK_RD_GO);
 995   2               }
 996   1      return 0xff;
 997   1      }


MODULE INFORMATION:   STATIC OVERLAYABLE
   CODE SIZE        =   7915    ----
   CONSTANT SIZE    =     59    ----
   XDATA SIZE       =   ----     164
   PDATA SIZE       =   ----    ----
   DATA SIZE        =     26      15
   IDATA SIZE       =   ----    ----
   BIT SIZE         =   ----    ----
END OF MODULE INFORMATION.


C51 COMPILATION COMPLETE.  10 WARNING(S),  0 ERROR(S)

⌨️ 快捷键说明

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