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

📄 sst39vf040.c.svn-base

📁 51单片机读写nor flash 读出flash 的ID
💻 SVN-BASE
📖 第 1 页 / 共 2 页
字号:
/************************************************************/
/* Copyright 2006,北京德彼克创新科技有限公司研发中心
*  All rights reserved.
*
*  文件名:SST39VF040.c
*  摘  要: FLASH存储
*
*  当前版本:1.0
*  作    者:轩松涛
*  完成日期: 2006/06/15                                       */
/*****************************************************************/



/*
Name                    Function
------------------------------------------------------------------
Check_SST_39VF040       Check manufacturer and device ID
Erase_Entire_Chip       Erase the contents of the entire chip
Erase_One_Sector        Erase a sector of 4096 bytes
Program_One_Byte        Alter data in one byte
Program_One_Sector      Alter data in 4096 bytes sector
Check_Toggle_Ready      End of internal program or erase detection using
                        Toggle bit
Check_Data_Polling      End of internal program or erase detection using
                        Data# polling


"C" LANGUAGE DRIVERS
*/


#include <REG51.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "STC89.h"
#include "SST39VF040.h"
#include "peripherals_control.h"

/* -------------------------------------------------------------------- */
/*                       EXTERNAL ROUTINES                              */
/* -------------------------------------------------------------------- */

//extern void     Delay_150_Nano_Seconds();
//extern void     Delay_20_Milli_Seconds();
//extern void     Delay_10_Milli_Seconds();

#ifdef sst

void  Delay_Nano_Seconds(int ntime)
{
   int i,j;
   for(i=0;i<ntime;i++)
      for(j=0;j<0xff;j++)
	  ;
}

/*************************************************************************/
/* PROCEDURE:   Check_SST_39VF040                                       */
/*                                                                      */
/* This procedure  decides whether a  physical hardware device has a    */
/* SST 39VF040 4 Mbit Multi-Purpose Flash installed or not.             */
/*                                                                      */
/* Input:                                                               */
/*          None                                                        */
/*                                                                      */
/* Output:                                                              */
/*          return TRUE:  indicates a SST 39VF040                       */
/*          return FALSE: indicates not a SST 39VF040                   */
/************************************************************************/


int Check_SST_39VF040()
{
        BYTE xdata  *Temp;
        BYTE SST_id1;
        BYTE SST_id2;
        int  ReturnStatus;
       
		/*  Issue the Software Product ID code to 39VF040   */
        Temp=(BYTE xdata *)0x5555;/* set up address to be A000:5555h  */
   	    *Temp = 0xAA;                   /* write data 0xAA to the address       */

   	    Temp=(BYTE xdata *)0x2AAA; /* set up address to be A000:2AAAh      */
        *Temp = 0x55;                  /* write data 0x55 to the address       */
        Temp= (BYTE xdata *)0x5555; /* set up address to be A000:5555h      */
        *Temp = 0x90;                   /* write data 0x90 to the address       */
  
        SELECT_PAGE(0);
        /* Read the product ID from 39VF040 */
 //       AUXR=0x02;  
	    Temp  = (BYTE xdata *)0x0000; /* set up address to be A000:0000h      */
        SST_id1  =  *Temp;              /* get first ID byte                    */
       	Temp  =  (BYTE xdata *)0x0001;/* set up address to be A000:0001h      */
        SST_id2  =  *Temp;              /* get first ID byte                    */
 //       AUXR=0x0;  
        /* Determine whether there is a SST 39VF040 installed or not */

        if ((SST_id1 == SST_ID) && (SST_id2 ==SST_39VF040))
              { 
 			     ReturnStatus = TRUE;
			  }
        else
           {
	        while(1);
	        ReturnStatus = FALSE;
           }
        /* Issue the Soffware Product ID Exit code thus returning the 39VF040   */
        /* to the read operating mode                                           */
         AUXR=0x0;  
        Temp  = (BYTE xdata *)0x5555; /* set up address to be A000:5555h      */
        *Temp = 0xAA;                   /* write data 0xAA to the address       */
        Temp  = (BYTE xdata *)0x2AAA; /* set up address to be A000:2AAAh      */
        *Temp = 0x55;                   /* write data 0x55 to the address       */
        Temp  = (BYTE xdata *)0x5555; /* set up address to be A000:5555h      */
        *Temp =0xF0;                    /* write data 0xF0 to the address       */

        Delay_Nano_Seconds(0x250);       /* check DATABOOK for the most  */
                                        /* accurate value -- Tida       */
        return(ReturnStatus);
}


/*************************************************************************/
/* PROCEDURE:   Erase_Entire_Chip                                       */
/*                                                                      */
/* This procedure can be used to erase the entire chip.                 */
/*                                                                      */
/* Input:                                                               */
/*      NONE                                                            */
/*                                                                      */
/* Output:                                                              */
/*      NONE                                                            */
/************************************************************************/

int Erase_Entire_Chip()
{
        BYTE xdata   *Temp;

        /*  Issue the Sector Erase command to 39VF040   */

        Temp  = (BYTE xdata*)0x5555; /* set up address to be A000:5555h      */
        *Temp = 0xAA;                   /* write data 0xAA to the address       */
        Temp  = (BYTE xdata*)0x2AAA; /* set up address to be A000:2AAAh      */
        *Temp = 0x55;                   /* write data 0x55 to the address       */
        Temp  = (BYTE xdata*)0x5555; /* set up address to be A000:5555h      */
        *Temp = 0x80;                  /* write data 0x80 to the address       */
        Temp  = (BYTE xdata*)0x5555; /* set up address to be A000:5555h      */
        *Temp = 0xAA;                   /* write data 0xAA to the address       */
        Temp  = (BYTE xdata*)0x2AAA; /* set up address to be A000:2AAAh      */
        *Temp = 0x55;                   /* write data 0x55 to the address       */
        Temp  = (BYTE xdata*)0x5555; /* set up address to be A000:5555h      */
        *Temp = 0x10;                   /* write data 0x55 to the address       */

        Delay_Nano_Seconds(250);
        return (0);
		//        Delay_100_Milli_Seconds();      /* check DATABOOK for the most  */
                                        /* accurate value -- Tsce       */
}



/*************************************************************************/
/* PROCEDURE:   Erase_One_Sector                                        */
/*                                                                      */
/* This procedure can be used to erase a total of 4096 bytes.           */
/*                                                                      */
/* Input:                                                               */
/*      iSector    sector which the erase operation will start         */
/*      iSector    0--128                                                      */
/* Output:                                                              */
/*      NONE                                                            */
/************************************************************************/

int Erase_One_Sector( int iSector)
{
       int iBlockNum,iSectorNum12; 
       BYTE xdata  *Temp;

        /*  Issue the Sector Erase command to 39VF040   */
        iBlockNum=iSector>>4;
		iSectorNum12=iSector%16; //BLOCK_SIZE;
		SELECT_PAGE(iBlockNum);

        Temp  = (BYTE xdata*)0x5555; /* set up address to be A000:5555h      */
        *Temp = 0xAA;                   /* write data 0xAA to the address       */
        Temp  = (BYTE xdata*)0x2AAA; /* set up address to be A000:2AAAh      */
        *Temp = 0x55;                  /* write data 0x55 to the address       */
        Temp  = (BYTE xdata*)0x5555; /* set up address to be A000:5555h      */
        *Temp = 0x80;                   /* write data 0x80 to the address       */
        Temp  = (BYTE xdata*)0x5555; /* set up address to be A000:5555h      */
        *Temp = 0xAA;                   /* write data 0xAA to the address       */
        Temp=(BYTE xdata*)0x2AAA; /* set up address to be A000:2AAAh      */
        *Temp = 0x55;                   /* write data 0x55 to the address       */
         Temp = (BYTE xdata *)(iSectorNum12<<12);                     /* set up starting address to be erased */
        *Temp = 0x30;                   /* write data 0xAA to the address       */

		 Delay_Nano_Seconds(250);
         return (0);
}


/************************************************************************/
/* PROCEDURE:   Program_One_Byte                                        */
/*                                                                      */
/* This procedure can be used to program ONE byte of data to the        */

⌨️ 快捷键说明

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