📄 sst39vf088.c.svn-base
字号:
/************************************************************/
/* Copyright 2006,北京德彼克创新科技有限公司研发中心
* All rights reserved.
*
* 文件名:SST39VF088.c
* 摘 要: FLASH存储
*
* 当前版本:1.0
* 作 者:轩松涛
* 完成日期: 2006/06/15 */
/*****************************************************************/
/*
Name Function
------------------------------------------------------------------
Check_SST_39VF088 Check manufacturer and device ID
Erase_Entire_Chip_VF088 Erase the contents of the entire chip
Erase_One_Sector_VF088 Erase a sector of 4096 bytes
Program_One_Byte_VF088 Alter data in one byte
Program_One_Sector_VF088 Alter data in 4096 bytes sector
Check_Toggle_Ready_VF088 End of internal program or erase detection using
Toggle bit
Check_Data_Polling_VF088 End of internal program or erase detection using
Data# polling
"C" LANGUAGE DRIVERS
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "STC89C516.h"
#include "test_gui.h"
#include "SST39VF088.h"
#include "peripherals_control.h"
#include "cl_main.h"
/* -------------------------------------------------------------------- */
/* EXTERNAL ROUTINES */
/* -------------------------------------------------------------------- */
//extern void Delay_150_Nano_Seconds();
//extern void Delay_20_Milli_Seconds();
//extern void Delay_10_Milli_Seconds();
void Delay_Nano_Seconds(int ntime)
{
int i,j;
for(i=0;i<ntime;i++)
for(j=0;j<0xff;j++);
}
#if 0
/*************************************************************************/
/* PROCEDURE: Check_SST_39VF088 */
/* */
/* This procedure checks if it's SST39VF088 8 Mbit Multi-Purpose Flash. */
/* */
/* Input: NONE */
/* */
/* Output: BFD8h for SST39VF088, */
/* Any other value indicates non SST39VF088. */
/* High byte returns vendor ID, low byte is device ID. */
/************************************************************************/
BYTE Check_SST_39VF088()
{
BYTE xdata *Temp;
BYTE SST_id1;
BYTE SST_id2;
BYTE ReturnStatus;
/* Issue the Software Product ID code to 39VF088 */
Temp=(BYTE xdata *)0xAAA; /* set up address to be AAAh */
*Temp = 0xAA; /*1st write data AAH to device addr AAAH*/
Temp=(BYTE xdata *)0x555; /* set up address to be 555h */
*Temp = 0x55; /* 2nd write data 55H to device addr 555H */
Temp= (BYTE xdata *)0xAAA; /* set up address to be AAAh */
*Temp = 0x90; /*3rd write data 90H to device addr AAAH */
SELECT_PAGE(0);
/* Read the product ID from 39VF040 */
// AUXR=0x02;
Temp = (BYTE xdata *)0x0000; /* set up address to be 0000h */
SST_id1 = *Temp; /* get first ID byte */
Temp = (BYTE xdata *)0x0001;/* set up address to be 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_39VF088))
{
ReturnStatus = TRUE;
}
else
{
ReturnStatus = FALSE;
}
/* Issue the Soffware Product ID Exit code thus returning the 39VF040 */
/* to the read operating mode */
// AUXR=0x0;
Temp = (BYTE xdata *)0x1234; /* set up address to be 1234h */
*Temp =0xF0; /* write data F0H into any device addr such as 1234H */
Delay_Nano_Seconds(0x250); /* check DATABOOK for the most */
/* accurate value -- Tida */
return(ReturnStatus);
}
/*************************************************************************/
/* PROCEDURE: Erase_Entire_Chip_VF088 */
/* */
/* This procedure erases the entire chip. */
/* */
/* Input: NONE. */
/* */
/* Output: TRUE if success, otherwise FALSE if timeout. */
/************************************************************************/
BYTE Erase_Entire_Chip_VF088()
{
BYTE xdata *Temp;
BYTE ReturnStatus=TRUE;
/* Issue the Sector Erase command to 39VF040 */
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 = 0x80; /* write data 0x80 to the address */
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 = 0x10; /* write data 0x55 to the address */
// ReturnStatus=Check_Data_Polling_VF088 ((BYTE xdata *)0, 0xff);
Delay_Nano_Seconds(250); /* check DATABOOK for the most */
return ReturnStatus;
}
/************************************************************************/
/* PROCEDURE: Erase_One_Block */
/* */
/* This procedure erases one block with total 64KByte. */
/* */
/* Input: Dst Address of Block to be erased. */
/* */
/* Output: TRUE if success, otherwise FALSE if timeout. */
/************************************************************************/
BYTE Erase_One_Block (int iBlock)
{
BYTE ReturnStatus=TRUE;
BYTE xdata *DestBuf;
BYTE xdata *Temp;
SELECT_PAGE(iBlock);
DestBuf = (BYTE xdata*)0;
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 = 0x80; /* write data 0x80 to the address */
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 = DestBuf; /* set up starting address to be erased */
*Temp = 0x30; /* write data 0x50 to the address */
// ReturnStatus=Check_Data_Polling_VF088 (Temp, 0xff);
Delay_Nano_Seconds(250);
return ReturnStatus;
}
#endif
/*************************************************************************/
/* PROCEDURE: Erase_One_Sector_VF088 */
/* */
/* This procedure erases one sector with total 4KByte. */
/* */
/* Input: Dst Address of Sector to be erased. */
/* */
/* Output: TRUE if success, otherwise FALSE if timeout. */
/************************************************************************/
BYTE Erase_One_Sector_VF088( int iSector)
{
int iBlockNum;
int iSectorNum;
BYTE xdata *Temp;
BYTE xdata *DestBuf;
BYTE ReturnStatus=TRUE;
iSectorNum=iSector;
iBlockNum=iSector>>4;
SELECT_PAGE(iBlockNum);
DestBuf = (BYTE xdata*)0;
DestBuf=((int)DestBuf)|((iSectorNum%16)<<12);
// Issue the Sector Erase command to 39VF088
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 = 0x80; // write data 0x80 to the address
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 = DestBuf; // set up starting address to be erased
*Temp = 0x50; // write data 0x50 to the address
//ReturnStatus=Check_Data_Polling_VF088 (Temp, 0xff);
Delay_Nano_Seconds(25);
return ReturnStatus;
}
/************************************************************************/
/* PROCEDURE: Check_Toggle_Ready_VF088 */
/* */
/* During the internal program cycle, any consecutive read operation */
/* on DQ6 will produce alternating 0's and 1's i.e. toggling between */
/* 0 and 1. When the program cycle is completed, DQ6 of the data will */
/* stop toggling. After the DQ6 data bit stops toggling, the device is */
/* ready for next operation. */
/* */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -