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

📄 sst39vf088.c.svn-base

📁 51单片机读写nor flash 读出flash 的ID
💻 SVN-BASE
📖 第 1 页 / 共 2 页
字号:
/* Input:                                                               */
/*           Dst        must already set-up by the caller               */
/*                                                                      */
/* Output:                                                              */
/*           None                                                       */
/************************************************************************/
BYTE Check_Toggle_Ready_VF088 (BYTE xdata *Dst)
{
       BYTE PreData;
       BYTE CurrData;
       ULONG TimeOut = 0;

       PreData = *Dst;
       PreData = PreData & 0x40;
       while (TimeOut< 0x00FFFFFF) 
       {
            CurrData = *Dst;
            CurrData = CurrData & 0x40;
            if (PreData == CurrData)
                  return TRUE;   // ready to exit the while loop 
            PreData = CurrData;
            TimeOut++;
       }
	return FALSE;

}
/************************************************************************/
/* PROCEDURE:   Program_One_Byte_VF088                                        */
/*                                                                      */
/* This procedure can be used to program ONE byte of data to the        */
/* 39VF040.                                                             */
/*                                                                      */
/* NOTE:  It is VERY important the sector containing the byte to be     */
/*        programmed was ERASED first.                                  */
/*                                                                      */
/* Input:                                                               */
/*           Src      The BYTE which will be written to the 39VF040.     */
/*           Dst      DESTINATION address which will be written with the */
/*                    data passed in from Src                            */
///*        iSector  the sector number which will be written to         */                                                          */
/* Output:                                                              */
/*           None                                                       */
/************************************************************************/
BYTE Program_One_Byte_VF088 (BYTE SrcByte,  int iSector, BYTE xdata *Dst)
{
	int iBlockNum; 
	BYTE xdata  *Temp;
	BYTE xdata  *DestBuf;
	BYTE  ReturnStatus=TRUE;

	iBlockNum=iSector>>4;
	SELECT_PAGE(iBlockNum);
	DestBuf = Dst;
	DestBuf=((int)DestBuf)|((iSector%16)<<12);
	//DestBuf =(BYTE xdata*)0x500;        

	Temp =  (BYTE xdata *)0xAAA; //set up address to be AAAh       
	*Temp = 0xAA;                   // write data 0xAA to the address       
	Temp =  (BYTE xdata *)0x555; // set up address to be 555h      
	*Temp = 0x55;                   // write data 0x55 to the address       
	Temp =  (BYTE  xdata *)0xAAA; // set up address to be AAAh      
	*Temp = 0xA0;                   // write data 0xA0 to the address      
	*DestBuf = SrcByte;             // transfer the byte to destination     
	//Delay_Nano_Seconds(4);
	ReturnStatus=Check_Toggle_Ready_VF088(DestBuf);    // wait for TOGGLE bit to get ready    
	
	return ReturnStatus;
}


/************************************************************************/
/* PROCEDURE:   Program_One_Sector_VF088                                     */
/*                                                                      */
/* This procedure can be used to program a total of 4096 bytes of date  */
/* to the SST's 39VF088.                                                */
/*                                                                      */
/* Input:                                                               */
/*           Src     SOURCE address containing the data which will be   */
/*                   written to the 39VF040.                            */
/*           iSector the sector which  data will be written to          */
/*           iSector  0--128                                            */
/* Output:                                                              */
/*           None                                                       */
/************************************************************************/
#if 0
void Program_One_Sector_VF088 (BYTE *Src, int iSector)
{
        unsigned int Index;
        Erase_One_Sector_VF088(iSector);          /* erase the sector first */
	    for (Index = 0; Index < SECTOR_SIZE; Index++)
        {
            Program_One_Byte_VF088 (*(Src+Index), iSector, (BYTE xdata *)Index);
   	    }
}



#endif

/************************************************************************/
/* PROCEDURE:   Check_Data_Polling_VF088                                      */
/*                                                                      */
/* During the internal program cycle, any attempt to read DQ7 of the    */
/* last byte loaded during the page/byte-load cycle will receive the    */
/* complement of the true data.  Once the program cycle is completed,   */
/* DQ7 will show true data.                                             */
/*                                                                      */
/* Input:                                                               */
/*           Dst        must already set-up by the caller               */
/*           True       Datathis is the original (true) data            */
/*                                                                      */
/* Output:                                                              */
/*           None                                                       */
/************************************************************************/
#if 0
BYTE Check_Data_Polling_VF088 (BYTE xdata *Dst, BYTE TrueData)
{

        BYTE CurrData;
        unsigned long TimeOut = 0;

        TrueData = TrueData &  0x80;
        while (TimeOut< 0x00FFFFFF) 
        {
                CurrData = *Dst;
                CurrData = CurrData & 0x80;
                if (TrueData == CurrData)
                       return TRUE;   /* ready to exit the while loop  */
                TimeOut++;
        }
		return FALSE;
}

#endif
#if 0
/************************************************************************/
/* PROCEDURE:   Program_Flash_VF088                                          */
/*                                                                      */
/* This procedure can be used to program data to the                    */
/* 39VF088.                                                             */
/*                                                                      */
/* NOTE:  It is VERY important the sector containing the byte to be     */
/*        programmed was ERASED first.                                  */
/*                                                                      */
/* Input:                                                               */
/*           Src     The BYTE which will be written to the 39VF088.     */
/*           iSector   the sector which the data will be  written to    */
/*                     iSector 0--256                                  */
///*          ulLeng    the length which will be writted to flash       */                                                     */
/* Output:                                                              */
/*           None                                                       */
/************************************************************************/
int Program_Flash_VF088(BYTE * src,int iSector,unsigned long ulLength)
{

   unsigned int Index;
   unsigned int i;
   unsigned int len;
   unsigned int SectorStart;
   unsigned int numSector;
   len=ulLength;
   SectorStart=iSector;   //起始sector
   numSector=ulLength/SECTOR_SIZE;               //待擦除扇区数
   if(ulLength%SECTOR_SIZE)
      numSector++;
     
   for(i=0;i<numSector;i++)
     {
     
	   Erase_One_Sector_VF088(i+SectorStart);  //擦除FLASH
       len-=i*SECTOR_SIZE;
       if(len>=SECTOR_SIZE)
       {
	   //         Program_One_Sector_VF088 (src+i*SECTOR_SIZE, SectorStart+i);  //写整个扇区
          for (Index = 0; Index < SECTOR_SIZE; Index++)
         {
            Program_One_Byte_VF088 (*(src+i*SECTOR_SIZE+Index), SectorStart+i, (BYTE xdata *)Index);
   	     }
	   }
       else
	    {  
	      for(Index=0;len>0;Index++)
		   { 
		    Program_One_Byte_VF088 (*(src+i*SECTOR_SIZE+Index),SectorStart+i,(BYTE xdata*)Index);//写剩余字节
            len--;
			} 
		}
	  }

   return (0);
}

#endif

/////////////////////////////////////////////////////////////////////////////
/*---------------------------------------------------------------------------

写BMP文件到FLASH指定位置

作者:赵春生
----------------------------------------------------------------------------*/

//////////////////////////////////////////////////////////////////////////////////
int Program_BMP_to_Flash(WORD iSector,ULONG ulLength)
{
	WORD Index;
	WORD i;
	ULONG len;
	WORD SectorStart;
	WORD numSector;
	len=ulLength;
	SectorStart=iSector;   //起始sector
	numSector=ulLength/SECTOR_SIZE;               //待擦除扇区数
	if(ulLength%SECTOR_SIZE)
		numSector++;

	for(i=0;i<numSector;i++)
	{
		Erase_One_Sector_VF088(i+SectorStart);  //擦除FLASH
		len=ulLength-i*SECTOR_SIZE; // debug by gqy	
		if(len>=SECTOR_SIZE)
		{
			//Program_One_Sector_VF088 (src+i*SECTOR_SIZE, SectorStart+i);  //写整个扇区
			for (Index = 0; Index < SECTOR_SIZE; Index++)
				Program_One_Byte_VF088 (GetBufData(), SectorStart+i, (BYTE xdata *)Index);
		}
		else
		{  
			for(Index=0;len>0;Index++)
			{ 
				Program_One_Byte_VF088 (GetBufData(),SectorStart+i,(BYTE xdata*)Index);//写剩余字节
				len--;
			} 
		}
	}

	return 0;
}

⌨️ 快捷键说明

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