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

📄 hpi32.lst

📁 完整的单片机读写SD卡程序
💻 LST
📖 第 1 页 / 共 4 页
字号:
 678   1                      return FALSE;
 679   1              if((len+32)>DeviceInfo.BPB_BytesPerSec)
 680   1                      return FALSE;
 681   1      
 682   1              ThisFile.bFileOpen=0;
 683   1              ThisFile.FatSectorPointer=0;
 684   1      
 685   1              cnum=GetFreeCusterNum32();
 686   1              if(cnum<0x02)
 687   1                      return FALSE;   
 688   1              
 689   1              pBuffer[11]=0x10;
 690   1              pBuffer[21]=(unsigned char)(cnum>>24);
 691   1              pBuffer[20]=(unsigned char)(cnum>>16);
 692   1              pBuffer[27]=(unsigned char)(cnum>>8);
 693   1              pBuffer[26]=(unsigned char)(cnum);
 694   1              pBuffer[28]=0;pBuffer[29]=0;pBuffer[30]=0;pBuffer[31]=0;
 695   1              bstop=0;
 696   1      
 697   1              NowCluster32=DirStartCluster32;         
 698   1                      do
 699   1                      {
 700   2                              NowSector=FirstSectorofCluster32(NowCluster32);
 701   2                              ClusterPointer=NowCluster32;
 702   2                              for(sector=0;sector<DeviceInfo.BPB_SecPerClus;sector++)
 703   2                      {   
 704   3                                      if(!SdReadSector(NowSector+sector,1,DBUF))
 705   3                                              return FALSE;
 706   3                                      DirCount=0;bwrite=0;
 707   3                                      for(i=0;i<DeviceInfo.BPB_BytesPerSec;i=i+32)
 708   3                                      {
 709   4                                      if(len==0)
 710   4                                              {
 711   5                                              if((DBUF[i]==0x00)||(DBUF[i]==0xE5))
 712   5                                              {
 713   6                                              for(j=0;j<32;j++)
 714   6                                                      DBUF[i+j]=*(pBuffer+j);
 715   6                                              if(!SdWriteSector(NowSector+sector,1,DBUF))
 716   6                                                      return FALSE;                                   
 717   6                                              bstop=1;
 718   6                                              break;
 719   6                                              }               
 720   5                                              }
 721   4                                      else
 722   4                                      {
 723   5                                      if(DirCount==0)
 724   5                                              InByte=i;
 725   5                                      if(DBUF[i]==0xE5)                               
 726   5                                              DirCount++;                             
 727   5                                      else if(DBUF[i]==0x00)
 728   5                                              {       
 729   6                                              DirCount++;     
 730   6                                              DBUF[i]=0xE5;
 731   6                                              bwrite=1;                                       
 732   6                                              }
 733   5                                      else
 734   5                                              DirCount=0;
 735   5      
 736   5                                      if((DirCount*32)>=(len+32))
 737   5                                              {
C51 COMPILER V8.02   HPI32                                                                 04/29/2007 12:48:53 PAGE 13  

 738   6                                              for(j=0;j<len;j++)
 739   6                                                      DBUF[InByte+j]=*(pName+j);
 740   6                                              for(j=0;j<32;j++)
 741   6                                                      DBUF[InByte+len+j]=*(pBuffer+j);
 742   6                                              if(!SdWriteSector(NowSector+sector,1,DBUF))
 743   6                                                      return FALSE;                                   
 744   6                                              bstop=1;
 745   6                                              break;
 746   6                                              }
 747   5                                       }                      
 748   4                                      }
 749   3                                      if(bstop==1)break;
 750   3                                      if((len!=0)&&(bwrite==1))
 751   3                                      {
 752   4                                      if(!SdWriteSector(NowSector+sector,1,DBUF))
 753   4                                              return FALSE;
 754   4                              }
 755   3                      }
 756   2                              if(bstop==1)break;
 757   2              
 758   2                              NowCluster32=GetNextClusterNum32(NowCluster32);
 759   2                              if(NowCluster32>DeviceInfo.TotCluster)
 760   2                      {
 761   3                              NowCluster32=CreateClusterLink32(ClusterPointer);
 762   3                              if(NowCluster32==0x00)
 763   3                                       return FALSE;
 764   3                              NowSector=FirstSectorofCluster32(NowCluster32);
 765   3                              for(i=0;i<DeviceInfo.BPB_BytesPerSec;i++) DBUF[i]=0x00;
 766   3                              for(sector=0;sector<DeviceInfo.BPB_SecPerClus;sector++)
 767   3                                      {
 768   4                                      if(!SdWriteSector(NowSector+sector,1,DBUF))
 769   4                                              return FALSE;
 770   4                                      }
 771   3                              }
 772   2                      }while(NowCluster32<=DeviceInfo.TotCluster);
 773   1              
 774   1              if(NowCluster32>DeviceInfo.TotCluster)
 775   1                  return FALSE;
 776   1      ////////////////////////////////////////////////////////////////
 777   1              for(i=64;i<DeviceInfo.BPB_BytesPerSec;i++)      DBUF[i]=0x00;
 778   1              
 779   1              for(i=0;i<43;i++) DBUF[i]=0x20;
 780   1              
 781   1              DBUF[0]=0x2e;
 782   1              for(i=11;i<32;i++) DBUF[i]=pBuffer[i];
 783   1      
 784   1              DBUF[32]=0x2e;DBUF[33]=0x2e;
 785   1              for(i=43;i<64;i++) DBUF[i]=pBuffer[i-32];
 786   1      
 787   1              if(DirStartCluster32==DeviceInfo.RootStartCluster)      //Root Dir
 788   1                      {
 789   2                      DBUF[53]=0;DBUF[52]=0;DBUF[59]=0;DBUF[58]=0;
 790   2                      }
 791   1              else
 792   1                      {
 793   2                      DBUF[53]=(unsigned char)(DirStartCluster32>>24);
 794   2                      DBUF[52]=(unsigned char)(DirStartCluster32>>16);
 795   2                      DBUF[59]=(unsigned char)(DirStartCluster32>>8);
 796   2                      DBUF[58]=(unsigned char)(DirStartCluster32);
 797   2                      }
 798   1      
 799   1              NowSector=FirstSectorofCluster32(cnum);
C51 COMPILER V8.02   HPI32                                                                 04/29/2007 12:48:53 PAGE 14  

 800   1              if(!SdWriteSector(NowSector,1,DBUF))
 801   1                      return FALSE;   
 802   1      
 803   1              DirStartCluster32=cnum;
 804   1      //      ThisFile.ClusterPointer=DirStartCluster32;
 805   1              ThisFile.ClusterPointer=0;              
 806   1              return TRUE;    
 807   1      }
 808          
 809          unsigned char DownDir32(unsigned char *pBuffer)
 810          {
 811   1              unsigned int i;
 812   1              unsigned char j,bstop,sector;   
 813   1                      
 814   1              if(!bFlags.bits.SLAVE_IS_ATTACHED)
 815   1                      return FALSE;   
 816   1              
 817   1              ThisFile.bFileOpen=0;
 818   1              bstop=0;
 819   1      
 820   1              NowCluster32=DirStartCluster32;         
 821   1                      do
 822   1                      {
 823   2                              NowSector=FirstSectorofCluster32(NowCluster32);
 824   2                              for(sector=0;sector<DeviceInfo.BPB_SecPerClus;sector++)
 825   2                      {   
 826   3                                      if(!SdReadSector(NowSector+sector,1,DBUF))
 827   3                                              return FALSE;                           
 828   3                                      for(i=0;i<DeviceInfo.BPB_BytesPerSec;i=i+32)
 829   3                                      {
 830   4                                              if(DBUF[i]==0x00)
 831   4                                                      return FALSE;
 832   4                                              j=0;
 833   4                                              while(DBUF[i+j]==*(pBuffer+j))
 834   4                                              {
 835   5                                                       j=j+1;
 836   5                                                       if(j>10)
 837   5                                                              break;
 838   5                                              }
 839   4                                              if(j>10&&(DBUF[i+11]&0x10))
 840   4                                              {bstop=1;break;}
 841   4                                      }
 842   3                                      if(bstop==1)break;              
 843   3                      }
 844   2                              if(bstop==1)break;      
 845   2                              NowCluster32=GetNextClusterNum32(NowCluster32);                 
 846   2                      }while(NowCluster32<=DeviceInfo.TotCluster);
 847   1                      
 848   1              if(NowCluster32>DeviceInfo.TotCluster)
 849   1                      return FALSE;
 850   1      
 851   1              DirStartCluster32=LSwapINT32(DBUF[i+26],DBUF[i+27],DBUF[i+20],DBUF[i+21]);      
 852   1      //      ThisFile.ClusterPointer=DirStartCluster32;
 853   1              ThisFile.ClusterPointer=0;              
 854   1              return TRUE;
 855   1      }
 856          
 857          unsigned char UpDir32()
 858          {
 859   1              if(!bFlags.bits.SLAVE_IS_ATTACHED)
 860   1                      return FALSE;   
 861   1              if(DirStartCluster32==DeviceInfo.RootStartCluster)      //Root Dir
C51 COMPILER V8.02   HPI32                                                                 04/29/2007 12:48:53 PAGE 15  

 862   1                      return TRUE;    
 863   1              
 864   1              ThisFile.bFileOpen=0;
 865   1      
 866   1              NowSector=FirstSectorofCluster32(DirStartCluster32);
 867   1              if(!SdReadSector(NowSector,1,DBUF))
 868   1                              return FALSE;
 869   1              if(DBUF[32]!=0x2e&&DBUF[33]!=0x2e)      //..
 870   1                              return FALSE;
 871   1      
 872   1              DirStartCluster32=LSwapINT32(DBUF[58],DBUF[59],DBUF[52],DBUF[53]);
 873   1              if(DirStartCluster32==0)        //Root Dir
 874   1                      DirStartCluster32=DeviceInfo.RootStartCluster;  
 875   1      //      ThisFile.ClusterPointer=DirStartCluster32;
 876   1              ThisFile.ClusterPointer=0;              
 877   1              return TRUE;
 878   1      }
 879          
 880          unsigned char UpRootDir32()
 881          {
 882   1              if(!bFlags.bits.SLAVE_IS_ATTACHED)
 883   1                      return FALSE;
 884   1      
 885   1              ThisFile.bFileOpen=0;
 886   1              DirStartCluster32=DeviceInfo.RootStartCluster;  //Root Dir
 887   1                              
 888   1              return TRUE;
 889   1      }
 890          


MODULE INFORMATION:   STATIC OVERLAYABLE
   CODE SIZE        =   8682    ----
   CONSTANT SIZE    =   ----    ----
   XDATA SIZE       =      8       6
   PDATA SIZE       =   ----    ----
   DATA SIZE        =   ----     136
   IDATA SIZE       =   ----    ----
   BIT SIZE         =   ----    ----
END OF MODULE INFORMATION.


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

⌨️ 快捷键说明

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