?? 39vf160.c
字號:
/* PROCEDURE: Erase_One_Block */
/* */
/* This procedure can be used to erase a total of 32K words. */
/* */
/* Input: */
/* Dst DESTINATION address which the erase operation starts */
/* */
/* Output: */
/* NONE */
/************************************************************************/
int Erase_One_Block (WORD far *Dst)
{
WORD far *Temp;
/* Issue the Sector Erase command to 39VF160 */
Temp = (WORD far *)0xC0005555; /* set up address to be C000:5555h */
*Temp = 0xAAAA; /* write data 0xAAAA to the address */
Temp = (WORD far *)0xC0002AAA; /* set up address to be C000:2AAAh */
*Temp = 0x5555; /* write data 0x5555 to the address */
Temp = (WORD far *)0xC0005555; /* set up address to be C000:5555h */
*Temp = 0x8080; /* write data 0x8080 to the address */
Temp = (WORD far *)0xC0005555; /* set up address to be C000:5555h */
*Temp = 0xAAAA; /* write data 0xAAAA to the address */
Temp = (WORD far *)0xC0002AAA; /* set up address to be C000:2AAAh */
*Temp = 0x5555; /* write data 0x5555 to the address */
Temp = Dst /* set up starting address to be erased */
*Temp = 0x5050; /* write data 0x5050 to the address */
Delay_25_Milli_Seconds(); /* Delay time = Tbe */
}
/************************************************************************/
/* PROCEDURE: Program_One_Word */
/* */
/* This procedure can be used to program ONE word of date to the */
/* 39VF160. */
/* */
/* NOTE: It is VERY important the sector containing the word to be */
/* programmed was ERASED first. */
/* */
/* Input: */
/* Src The WORD which will be written to the 39VF160 */
/* Dst DESTINATION address which will be written with the */
/* data passed in from Src */
/* */
/* Output: */
/* None */
/************************************************************************/
void Program_One_Word (WORD SrcWord, WORD far *Dst)
{
WORD far *SourceBuf;
WORD far *DestBuf;
int Index;
DestBuf = Dst;
Temp = (WORD far *)0xC0005555; /* set up address to be C000:555h */
*Temp = 0xAAAA; /* write data 0xAAAA to the address */
Temp = (WORD far *)0xC0002AAA; /* set up address to be C000:2AAAh */
*Temp = 0x5555; /* write data 0x5555 to the address */
Temp = (WORD far *)0xC0005555; /* set up address to be C000:5555h */
*Temp = 0xA0A0; /* write data 0xA0A0 to the address */
*DestBuf = SrcWord; /* transfer the byte to destination */
Check_Toggle_Ready(DestBuf); /* wait for TOGGLE bit to get ready */
}
/************************************************************************/
/* PROCEDURE: Program_One_Sector */
/* */
/* This procedure can be used to program a total of 2048 words of data */
/* to the SST39VF160. */
/* */
/* Input: */
/* Src SOURCE address containing the data which will be */
/* written to the 39VF160 */
/* Dst DESTINATION address which will be written with the */
/* data passed in from Src */
/* */
/* Output: */
/* None */
/************************************************************************/
void Program_One_Sector (WORD far *Src, WORD far *Dst)
{
WORD far *Temp;
WORD far *SourceBuf;
WORD far *DestBuf;
int Index;
SourceBuf = Src;
DestBuf = Dst;
Erase_One_Sector(Dst); /* erase the sector first */
for (Index = 0; Index < SECTOR_SIZE; Index++)
{
Temp = (WORD far *)0xC0005555; /* set up address to be C000:555h */
*Temp = 0xAAAA; /* write data 0xAAAA to the address */
Temp = (WORD far *)0xC0002AAA; /* set up address to be C000:2AAAh */
*Temp = 0x5555; /* write data 0x5555 to the address */
Temp = (WORD far *)0xC0005555; /* set up address to be C000:5555h */
*Temp = 0xA0A0; /* write data 0xA0A0 to the address */
Temp = DestBuf; /* save the original Destination address */
*DestBuf++ = *SourceBuf++; /* transfer data from source to destination */
Check_Toggle_Ready(Temp); /* wait for TOGGLE bit to get ready */
}
}
/************************************************************************/
/* PROCEDURE: Program_One_Block */
/* */
/* This procedure can be used to program a total of 32k words of data */
/* to the SST39VF160. */
/* */
/* Input: */
/* Src SOURCE address containing the data which will be */
/* written to the 39VF160 */
/* Dst DESTINATION address which will be written with the */
/* data passed in from Src */
/* */
/* Output: */
/* None */
/************************************************************************/
void Program_One_Block (WORD far *Src, WORD far *Dst)
{
WORD far *Temp;
WORD far *SourceBuf;
WORD far *DestBuf;
int Index;
SourceBuf = Src;
DestBuf = Dst;//dst 寫是地址
Erase_One_Block(Dst); /* erase the sector first */
for (Index = 0; Index < BLOCK_SIZE; Index++)
{
Temp = (WORD far *)0xC0005555; /* set up address to be C000:555h */
*Temp = 0xAAAA; /* write data 0xAAAA to the address */
Temp = (WORD far *)0xC0002AAA; /* set up address to be C000:2AAAh */
*Temp = 0x5555; /* write data 0x5555 to the address */
Temp = (WORD far *)0xC0005555; /* set up address to be C000:5555h */
*Temp = 0xA0A0; /* write data 0xA0A0 to the address */
Temp = DestBuf; /* save the original Destination address */
*DestBuf++ = *SourceBuf++; /* transfer data from source to destination */
Check_Toggle_Ready(Temp); /* wait for TOGGLE bit to get ready */
}
}
/************************************************************************/
/* PROCEDURE: Check_Toggle_Ready */
/* */
/* 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. */
/* */
/* Input: */
/* Dst must already set-up by the caller */
/* */
/* Output: */
/* None */
/************************************************************************/
void Check_Toggle_Ready (WORD far *Dst)
{
BYTE Loop = TRUE;
WORD PreData;
WORD CurrData;
unsigned long TimeOut = 0;
PreData = *Dst;
PreData = PreData & 0x4040;
while ((TimeOut< 0x07FFFFFF) && (Loop))
{
CurrData = *Dst;//讀回數(shù)據(jù)
CurrData = CurrData & 0x4040; //比較D6位的值,如果兩次讀回來一樣,那么就是對的。
if (PreData == CurrData) //如果和寫之前一樣,表示可以退出循環(huán)。
{
Loop = FALSE; /* ready to exit the while loop */
}
PreData = CurrData;
TimeOut++;
}
}
/************************************************************************/
/* PROCEDURE: Check_Data_Polling */
/* */
/* 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 Data is the original (true) data */
/* */
/* Output: */
/* None */
/************************************************************************/
void Check_Data_Polling (WORD far *Dst, WORD TrueData)
{
BYTE Loop = TRUE;
WORD CurrData;
unsigned long TimeOut = 0;
TrueData = TrueData & 0x8080;
while ((TimeOut< 0x07FFFFFF) && (Loop))
{
CurrData = *Dst;
CurrData = CurrData & 0x8080;
if (TrueData == CurrData)
Loop = FALSE; /* ready to exit the while loop */
TimeOut++;
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -