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

📄 hpi.lst

📁 ms51 控制sl811读写u盘的源程序 及 原理图 可仿真试一下
💻 LST
📖 第 1 页 / 共 3 页
字号:
 578   2      		   {	
 579   3      		   	ThisFile.OffsetofSector-=step*DeviceInfo.BPB_BytesPerSec;
 580   3      		   	ThisFile.SectorofCluster+=step;
 581   3      		   	if(ThisFile.SectorofCluster>DeviceInfo.BPB_SecPerClus-1)
 582   3      		   	{
 583   4      		   		ThisFile.SectorofCluster=0;
 584   4      		   		if(ThisFile.pointer+UartRspBlock.len<ThisFile.LengthInByte)
 585   4      		   			ThisFile.ClusterPointer=GetNextClusterNum(ThisFile.ClusterPointer);
 586   4      		   		else
 587   4      		 		 	ThisFile.ClusterPointer=CreateClusterLink(ThisFile.ClusterPointer);//GetNextClusterNum(ThisFile.Clu
             -sterPointer);
 588   4      		 		 if(ThisFile.ClusterPointer==0x00)
 589   4      		 		 	{
 590   5      		 		 //	   RspBlockReadFile.errcode=ERC_REACHEND;
 591   5      		   			//   RspBlockReadFile.result=0x0;
 592   5      		   			UartRspBlock.errcode=ERC_DEVICEERR;
 593   5      					return FALSE;	
 594   5      		 			}
 595   4      		 		 ThisFile.SectorPointer=FirstSectorofCluster(ThisFile.ClusterPointer); 	
 596   4      		   	}
 597   3      		   	else
 598   3      		   		ThisFile.SectorPointer=ThisFile.SectorPointer+step;
 599   3      		    }
 600   2      		
 601   2      	
 602   2      	}//end while
 603   1      	ThisFile.pointer+=UartRspBlock.len;
 604   1      	
 605   1      	UpdateFat(FreeFat.SectorNum);
 606   1      	///////////更新文件目录信息/////////////////////////////
 607   1      	if(bSuccess==1)
 608   1      	{
 609   2      		
 610   2      		for(sector=0;sector<DeviceInfo.BPB_RootEntCnt;sector++)
 611   2      	    	{   
 612   3      		//////////////////////////////////////////////////
C51 COMPILER V6.20c  HPI                                                                   08/21/2003 22:51:03 PAGE 11  

 613   3      		if(!RBC_Read(DeviceInfo.RootStartSector+sector,1,DBUF))
 614   3      			{
 615   4      			UartRspBlock.errcode=ERC_DEVICEERR;
 616   4      			return FALSE;	
 617   4      			}
 618   3      		///////////////////////////////////////////////////
 619   3      		for(i=0;i<DeviceInfo.BPB_BytesPerSec;i=i+32)
 620   3      			{
 621   4      			pDirInfo=(PDIR_INFO)(DBUF+i);
 622   4      			
 623   4      			if(pDirInfo->startCluster==SwapINT16(ThisFile.StartCluster))
 624   4      				{
 625   5      				if(ThisFile.pointer>ThisFile.LengthInByte)
 626   5      					ThisFile.LengthInByte=ThisFile.pointer;
 627   5      				//else
 628   5      				//	ThisFile.pointer=;
 629   5      				
 630   5      				pDirInfo->length=SwapINT32(ThisFile.LengthInByte);
 631   5      				if(!RBC_Write(DeviceInfo.RootStartSector+sector,1,DBUF))
 632   5      		   		{
 633   6      		   		UartRspBlock.errcode=ERC_DEVICEERR;
 634   6      				return FALSE;	
 635   6      		   		}
 636   5      				 bStop=1;
 637   5      				 break;
 638   5      				}
 639   4      			}
 640   3      		if(bStop==1)
 641   3      			break;
 642   3      		////////////////////////////////////////////////////
 643   3      	       }
 644   2      	
 645   2      	}
 646   1      	/*
 647   1      	if(bSuccess==0)
 648   1      	{
 649   1      	RspBlockWriteFile.errcode=ERC_DEVICEERR;
 650   1      	RspBlockWriteFile.result=0x0;
 651   1      	}
 652   1      	*/
 653   1      	UartRspBlock.len=0;
 654   1      	ThisFile.bFileOpen=1;
 655   1      	//////////////////////////////////////////////
 656   1      	return TRUE;
 657   1      #undef RspBlockWriteFile
 658   1      }
 659          
 660          unsigned char RemoveFile(unsigned char *pBuffer)
 661          {
 662   1      #define RspBlockRemoveFile UartRspBlock.RspBlock.Rsp_RemoveFile
 663   1      	unsigned int sector,i;
 664   1      	unsigned char bStop,j;
 665   1      	PDIR_INFO pDirInfo;
 666   1      	
 667   1      	if(!bXXGFlags.bits.SLAVE_IS_ATTACHED)
 668   1      	{
 669   2      	UartRspBlock.errcode=ERC_NODEVICE;
 670   2      	return FALSE;		
 671   2      	}
 672   1      	///////////////////////////////////////////////////////////
 673   1      	//RspBlockRemoveFile.result=0x1;
 674   1      	////////////// 清除目录/////////////////////////////////////
C51 COMPILER V6.20c  HPI                                                                   08/21/2003 22:51:03 PAGE 12  

 675   1      	for(sector=0;sector<DeviceInfo.BPB_RootEntCnt;sector++)
 676   1      	    	{   
 677   2      		//////////////////////////////////////////////////
 678   2      		if(!RBC_Read(DeviceInfo.RootStartSector+sector,1,DBUF))
 679   2      			{
 680   3      			UartRspBlock.errcode=ERC_DEVICEERR;
 681   3      			return FALSE;	
 682   3      			}
 683   2      		///////////////////////////////////////////////////
 684   2      		for(i=0;i<DeviceInfo.BPB_BytesPerSec;i=i+32)
 685   2      			{
 686   3      			if(DBUF[i]==0x00)
 687   3      				{
 688   4      				UartRspBlock.errcode=ERC_FILENOTFOUND;
 689   4      				return FALSE;	
 690   4      				}
 691   3      			///////////////////////////////////////////
 692   3      			j=0;
 693   3      			while(DBUF[i+j]==*(pBuffer+j))
 694   3      				{
 695   4      				 j=j+1;
 696   4      				 if(j>10) break;
 697   4      				 }//end while
 698   3      			
 699   3      			if(j>10)
 700   3      			 	{	
 701   4      			 	DBUF[i]=0xE5;
 702   4      			 	pDirInfo=(PDIR_INFO)(DBUF+i);
 703   4      			 	ThisFile.StartCluster=SwapINT16(pDirInfo->startCluster);
 704   4      			 	//DelayMs(15);
 705   4      			 	if(!RBC_Write(DeviceInfo.RootStartSector+sector,1,DBUF))
 706   4      					{
 707   5      					UartRspBlock.errcode=ERC_DEVICEERR;
 708   5      					return FALSE;	
 709   5      					}
 710   4      				//////////////////// 清除FAT中的纪录////////////////////////
 711   4      				//DelayMs(10);
 712   4      				if(!DeleteClusterLink(ThisFile.StartCluster))
 713   4      						{
 714   5      						UartRspBlock.errcode=ERC_DEVICEERR;
 715   5      						return FALSE;	
 716   5      						}
 717   4      			 	bStop=1;
 718   4      			 	break;
 719   4      			 	}
 720   3      			
 721   3      			}//end for
 722   2      		if(bStop==1)
 723   2      			break;
 724   2      		
 725   2      	       }//end search
 726   1      	if(sector>=DeviceInfo.BPB_RootEntCnt)
 727   1      		{
 728   2      		UartRspBlock.errcode=ERC_FILENOTFOUND;
 729   2      			return FALSE;	
 730   2      		}
 731   1      	//////////////////////////////////////////////
 732   1      	return TRUE;
 733   1      #undef RspBlockRemoveFile
 734   1      }
 735          
 736          unsigned char GetCapacity(void)
C51 COMPILER V6.20c  HPI                                                                   08/21/2003 22:51:03 PAGE 13  

 737          {
 738   1      	unsigned int sectorNum,freesectorcnt,i;
 739   1      	
 740   1      #define RspBlockGetCapacity UartRspBlock.RspBlock.Rsp_GetCapacity
 741   1      	PREAD_CAPACITY_RSP pBuf;
 742   1      	
 743   1      	if(!bXXGFlags.bits.SLAVE_IS_ATTACHED)
 744   1      	{
 745   2      	UartRspBlock.errcode=ERC_NODEVICE;
 746   2      	return FALSE;		
 747   2      	}
 748   1      	///////////////////////////////////////////////////////////
 749   1      	if(!RBC_ReadCapacity())
 750   1      	{
 751   2      	UartRspBlock.errcode=ERC_DEVICEERR;
 752   2      	return FALSE;	
 753   2      	}
 754   1      	
 755   1      	pBuf=(PREAD_CAPACITY_RSP)DBUF;
 756   1      	RspBlockGetCapacity.disksize=SwapINT32((pBuf->LastLBA+1)*pBuf->BlockSize);
 757   1      	////////////////////////////////////////////////////////////////////////
 758   1      	sectorNum=DeviceInfo.FatStartSector;
 759   1      	freesectorcnt=0;
 760   1      	while(sectorNum<DeviceInfo.BPB_FATSz16+DeviceInfo.FatStartSector)
 761   1      	{
 762   2      		
 763   2      		if(RBC_Read(sectorNum,1,DBUF))
 764   2      		{
 765   3      		  for(i=0;i<DeviceInfo.BPB_BytesPerSec;i=i+2)
 766   3      		  	{
 767   4      		  	 //clusterNum++;	
 768   4      		  	 
 769   4      		  	 if((DBUF[i]==0xff)&&(DBUF[i+1]==0xff))
 770   4      		  	 	{	
 771   5      		  	 	freesectorcnt++;
 772   5      		  	 	}
 773   4      		  	// clusterNum++;
 774   4      		  	}	
 775   3      		}
 776   2      		else
 777   2      			{
 778   3      			UartRspBlock.errcode=ERC_DEVICEERR;
 779   3      			return FALSE;	
 780   3      			}
 781   2      		sectorNum++;
 782   2      	}
 783   1      	
 784   1      	////////////////////////////////////////////////////////////////////////
 785   1      	RspBlockGetCapacity.freedisksize=DeviceInfo.BPB_BytesPerSec*DeviceInfo.BPB_SecPerClus;
 786   1      	RspBlockGetCapacity.freedisksize=freesectorcnt*RspBlockGetCapacity.freedisksize;
 787   1      	RspBlockGetCapacity.freedisksize=SwapINT32(RspBlockGetCapacity.disksize)-RspBlockGetCapacity.freedisksize
             -;
 788   1      	RspBlockGetCapacity.freedisksize=SwapINT32(RspBlockGetCapacity.freedisksize);
 789   1      		
 790   1      	return TRUE;
 791   1      #undef RspBlockGetCapacity
 792   1      }
 793          
 794          unsigned char GetFreeCapacity(void)
 795          {
 796   1      #define RspBlockGetCapacity UartRspBlock.RspBlock.Rsp_GetFreeCapacity
 797   1      	if(!bXXGFlags.bits.SLAVE_IS_ATTACHED)
C51 COMPILER V6.20c  HPI                                                                   08/21/2003 22:51:03 PAGE 14  

 798   1      	{
 799   2      	UartRspBlock.errcode=ERC_NODEVICE;
 800   2      	return FALSE;		
 801   2      	}
 802   1      	//////////////////////////////////////////////
 803   1      	
 804   1      	
 805   1      	return TRUE;
 806   1      #undef RspBlockGetFreeCapacity
 807   1      }
 808          
 809          unsigned char SetFilePointer(unsigned long pointer)
 810          {
 811   1      #define RspBlockSetFilePointer UartRspBlock.RspBlock.Rsp_SetFilePointer
 812   1      	
 813   1      	//ThisFile.FilePointer=UartCmdBlock.CmdBlock.Cmd_SetFilePointer.pointer;
 814   1      	if(!bXXGFlags.bits.SLAVE_IS_ATTACHED)
 815   1      	{
 816   2      	UartRspBlock.errcode=ERC_NODEVICE;
 817   2      	return FALSE;		
 818   2      	}
 819   1      	if(!ThisFile.bFileOpen)
 820   1      	{
 821   2      	UartRspBlock.errcode=ERC_FILENOTOPENED;
 822   2      	return FALSE;		
 823   2      	}
 824   1      	///////////////////////////////////////////////////////////
 825   1      	ThisFile.pointer=pointer;
 826   1      	if(ThisFile.pointer>ThisFile.LengthInByte)
 827   1      	{
 828   2      	UartRspBlock.errcode=ERC_LENGTHEXCEED;
 829   2      	return FALSE;	
 830   2      	}
 831   1      	
 832   1      	if(!GoToPointer(ThisFile.pointer))
 833   1      	{
 834   2      	ThisFile.bFileOpen=0;
 835   2      	UartRspBlock.errcode=ERC_DEVICEERR;
 836   2      	return FALSE;	
 837   2      	}
 838   1      	//////////////////////////////////////////////
 839   1      	return TRUE;
 840   1      
 841   1      #undef RspBlockSetFilePointer
 842   1      }
 843          
 844          unsigned char GetFirmwareVersion(void)
 845          {
 846   1         #define RspBlockGetVersion UartRspBlock.RspBlock.Rsp_GetVersion
 847   1         ////////////////////////////////////////////////////////////
 848   1         RspBlockGetVersion.version=0x0102;
 849   1         return TRUE;
 850   1         #undef RspBlockGetVersion
 851   1      }
 852          


MODULE INFORMATION:   STATIC OVERLAYABLE
   CODE SIZE        =   4746    ----
   CONSTANT SIZE    =   ----    ----
   XDATA SIZE       =  28895    ----
   PDATA SIZE       =   ----    ----
C51 COMPILER V6.20c  HPI                                                                   08/21/2003 22:51:03 PAGE 15  

   DATA SIZE        =   ----      82
   IDATA SIZE       =   ----       4
   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 + -