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

📄 hpi32.lst

📁 c51读写SD卡原代码,c51编写,串口接收
💻 LST
📖 第 1 页 / 共 4 页
字号:
 223   1              ThisFile.pointer=0;
 224   1              
 225   1              Response.len=32;
 226   1              return TRUE;    
 227   1      }
 228          
 229          
 230          unsigned char ReadFile32(unsigned long readLength,unsigned char *pBuffer)
 231          {
 232   1      
 233   1              unsigned int len,i;
 234   1              unsigned int tlen;      
 235   1              unsigned long blen;
 236   1      
 237   1              if(!bFlags.bits.SLAVE_IS_ATTACHED)
 238   1                      return FALSE;           
 239   1              if(!ThisFile.bFileOpen)
 240   1                      return FALSE;
 241   1      
C51 COMPILER V7.00  HPI32                                                                  02/15/2008 12:14:59 PAGE 5   

 242   1              blen=readLength;
 243   1              tlen=0;
 244   1              if(readLength>MAX_READ_LENGTH)
 245   1                      return FALSE;   
 246   1              
 247   1              if(readLength+ThisFile.pointer>ThisFile.LengthInByte)
 248   1                      return FALSE;   
 249   1                      
 250   1              ////////////////////////////////////////////            
 251   1                      while(readLength>0)
 252   1                      {
 253   2                         if(ThisFile.SectorofCluster>=DeviceInfo.BPB_SecPerClus)
 254   2                              {
 255   3                                      ThisFile.SectorofCluster=0;
 256   3                                       ThisFile.ClusterPointer=GetNextClusterNum32(ThisFile.ClusterPointer);
 257   3                                       if(ThisFile.ClusterPointer>DeviceInfo.TotCluster)
 258   3                                                 return FALSE;                                                
 259   3                                       ThisFile.SectorPointer=FirstSectorofCluster32(ThisFile.ClusterPointer);        
 260   3                              }
 261   2      
 262   2                         if(readLength+ThisFile.OffsetofSector>DeviceInfo.BPB_BytesPerSec)
 263   2                              len=DeviceInfo.BPB_BytesPerSec;
 264   2                         else
 265   2                              len=readLength+ThisFile.OffsetofSector;
 266   2                         
 267   2                         //////////////////////////////////////////////////////
 268   2                         if(ThisFile.OffsetofSector>0)
 269   2                              {
 270   3                              if(SdReadSector(ThisFile.SectorPointer,1,DBUF))
 271   3                                      {
 272   4                                      
 273   4                                      len=len-ThisFile.OffsetofSector;
 274   4                                      for(i=0;i<len;i++)
 275   4                                              
 276   4                                              *(pBuffer+i)=DBUF[ThisFile.OffsetofSector+i];
 277   4                                      ThisFile.OffsetofSector=ThisFile.OffsetofSector+len;
 278   4                                      }
 279   3                              else
 280   3                                      return FALSE;                           
 281   3                              }
 282   2                         else
 283   2                              {
 284   3                                      if(!SdReadSector(ThisFile.SectorPointer,1,pBuffer+tlen))
 285   3                                                      return FALSE;   
 286   3                                      ThisFile.OffsetofSector=len;
 287   3                              }
 288   2                         ////////////////////////////////////////////////////////////
 289   2                         readLength-=len;
 290   2                         tlen+=len;
 291   2                        
 292   2                         /////////////////////////////////////////////////////////
 293   2                         if(ThisFile.OffsetofSector>=DeviceInfo.BPB_BytesPerSec)
 294   2                         {    
 295   3                              ThisFile.OffsetofSector-=DeviceInfo.BPB_BytesPerSec;
 296   3                              ThisFile.SectorofCluster+=1;
 297   3                              
 298   3                               ThisFile.SectorPointer+=1;
 299   3                          }
 300   2                         //////////////////////////////////////////////////////////////////
 301   2                      }//end while
 302   1                      
 303   1              ThisFile.bFileOpen=1;
C51 COMPILER V7.00  HPI32                                                                  02/15/2008 12:14:59 PAGE 6   

 304   1              ThisFile.pointer+=tlen;
 305   1              //////////////////////////////////////////////
 306   1              Response.len=blen;
 307   1      
 308   1              return TRUE;
 309   1      }
 310          
 311          unsigned char SetFilePointer32(unsigned long pointer)
 312          {
 313   1              if(!bFlags.bits.SLAVE_IS_ATTACHED)
 314   1                      return FALSE;           
 315   1              if(!ThisFile.bFileOpen)
 316   1                      return FALSE;           
 317   1              ///////////////////////////////////////////////////////////
 318   1              ThisFile.pointer=pointer;
 319   1              if(ThisFile.pointer>ThisFile.LengthInByte)
 320   1                      return FALSE;   
 321   1      
 322   1              if(!GoToPointer32(ThisFile.pointer))
 323   1              {
 324   2              ThisFile.bFileOpen=0;
 325   2              return FALSE;   
 326   2              }
 327   1              //////////////////////////////////////////////
 328   1              return TRUE;
 329   1      }
 330          
 331          unsigned char CreateFile32(unsigned long len,unsigned char *pBuffer,unsigned char *pName)
 332          {
 333   1              unsigned int sector,i,j,DirCount;
 334   1          unsigned int xdata InByte;
 335   1              unsigned long cnum;
 336   1              unsigned char xdata bstop,bwrite;
 337   1              unsigned long ClusterPointer;
 338   1              
 339   1              if(!bFlags.bits.SLAVE_IS_ATTACHED)
 340   1                      return FALSE;
 341   1              if((len%32)!=0)
 342   1                      return FALSE;
 343   1              if((len+32)>DeviceInfo.BPB_BytesPerSec)
 344   1                      return FALSE;
 345   1      
 346   1              ThisFile.bFileOpen=0;   
 347   1      
 348   1              cnum=GetFreeCusterNum32();
 349   1              if(cnum<0x02)
 350   1                      return FALSE;   
 351   1      
 352   1              pBuffer[21]=(unsigned char)(cnum>>24);
 353   1              pBuffer[20]=(unsigned char)(cnum>>16);
 354   1              pBuffer[27]=(unsigned char)(cnum>>8);
 355   1              pBuffer[26]=(unsigned char)(cnum);
 356   1      
 357   1              pBuffer[28]=0;pBuffer[29]=0;pBuffer[30]=0;pBuffer[31]=0;
 358   1              bstop=0;
 359   1      
 360   1              NowCluster32=DirStartCluster32;         
 361   1                      do
 362   1                      {
 363   2                              NowSector=FirstSectorofCluster32(NowCluster32);
 364   2                              ClusterPointer=NowCluster32;
 365   2                              for(sector=0;sector<DeviceInfo.BPB_SecPerClus;sector++)
C51 COMPILER V7.00  HPI32                                                                  02/15/2008 12:14:59 PAGE 7   

 366   2                      {   
 367   3                                      if(!SdReadSector(NowSector+sector,1,DBUF))
 368   3                                              return FALSE;
 369   3                                      DirCount=0;bwrite=0;
 370   3      
 371   3                                      for(i=0;i<DeviceInfo.BPB_BytesPerSec;i=i+32)
 372   3                                      {
 373   4                                      if(len==0)
 374   4                                              {
 375   5                                              if((DBUF[i]==0x00)||(DBUF[i]==0xE5))
 376   5                                              {
 377   6                                              for(j=0;j<32;j++)
 378   6                                                      DBUF[i+j]=*(pBuffer+j);
 379   6                                              if(!SdWriteSector(NowSector+sector,1,DBUF))
 380   6                                                      return FALSE;                                   
 381   6                                              bstop=1;
 382   6                                              break;
 383   6                                              }               
 384   5                                              }
 385   4                                      else
 386   4                                      {
 387   5                                      if(DirCount==0)
 388   5                                              InByte=i;
 389   5                                      if(DBUF[i]==0xE5)                               
 390   5                                              DirCount++;                             
 391   5                                      else if(DBUF[i]==0x00)
 392   5                                              {       
 393   6                                              DirCount++;     
 394   6                                              DBUF[i]=0xE5;   
 395   6                                              bwrite=1;                               
 396   6                                              }
 397   5                                      else
 398   5                                              DirCount=0;
 399   5      
 400   5                                      if((DirCount*32)>=(len+32))
 401   5                                              {
 402   6                                              for(j=0;j<len;j++)
 403   6                                                      DBUF[InByte+j]=*(pName+j);
 404   6                                              for(j=0;j<32;j++)
 405   6                                                      DBUF[InByte+len+j]=*(pBuffer+j);
 406   6                                              if(!SdWriteSector(NowSector+sector,1,DBUF))
 407   6                                                      return FALSE;                                   
 408   6                                              bstop=1;
 409   6                                              break;
 410   6                                              }
 411   5                                       }
 412   4                                      }
 413   3                                      if(bstop==1)break;
 414   3                                      
 415   3                                      if((len!=0)&&(bwrite==1))
 416   3                                      {
 417   4                                      if(!SdWriteSector(NowSector+sector,1,DBUF))
 418   4                                              return FALSE;
 419   4                              }
 420   3                      }
 421   2                              if(bstop==1)break;
 422   2              
 423   2                              NowCluster32=GetNextClusterNum32(NowCluster32);
 424   2                              if(NowCluster32>DeviceInfo.TotCluster)
 425   2                      {
 426   3                              NowCluster32=CreateClusterLink32(ClusterPointer);
 427   3                              if(NowCluster32==0x00)
C51 COMPILER V7.00  HPI32                                                                  02/15/2008 12:14:59 PAGE 8   

 428   3                                       return FALSE;
 429   3                              NowSector=FirstSectorofCluster32(NowCluster32);
 430   3                              for(i=0;i<DeviceInfo.BPB_BytesPerSec;i++) DBUF[i]=0x00;
 431   3                              for(sector=0;sector<DeviceInfo.BPB_SecPerClus;sector++)
 432   3                                      {
 433   4                                      if(!SdWriteSector(NowSector+sector,1,DBUF))
 434   4                                              return FALSE;
 435   4                                      }
 436   3                              }
 437   2                      }while(NowCluster32<=DeviceInfo.TotCluster);    
 438   1      ////////////////////////////////////////////////////////////////
 439   1              
 440   1              ThisFile.StartCluster=cnum;
 441   1              ThisFile.LengthInByte=0;
 442   1              ThisFile.ClusterPointer=ThisFile.StartCluster;
 443   1              ThisFile.SectorPointer=FirstSectorofCluster32(ThisFile.StartCluster);
 444   1              ThisFile.OffsetofSector=0;
 445   1              ThisFile.SectorofCluster=0;
 446   1              ThisFile.bFileOpen=1;
 447   1              ThisFile.pointer=0;
 448   1              ThisFile.FatSectorPointer=0;
 449   1              
 450   1              return TRUE;
 451   1      }

⌨️ 快捷键说明

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