?? sst39vf160.c
字號(hào):
/****************************************************************************
* 文件名:SST39VF160.C
* 功能:對(duì)SST39VF160進(jìn)行全片擦除,然后寫兩字節(jié)數(shù)據(jù)到芯片0地址,再讀出來(lái)校驗(yàn),
* 若校驗(yàn)通過則蜂鳴器響一聲,否則不斷地蜂鳴報(bào)警。
* 說(shuō)明:將跳線器JP9短接,JP4斷開。
****************************************************************************/
#include "config.h"
#define BEEPCON 0x00000080 /* P0.7引腳控制B1,低電平蜂鳴 */
/****************************************************************************
* 名稱:DelayNS()
* 功能:長(zhǎng)軟件延時(shí)。
* 入口參數(shù):dly 延時(shí)參數(shù),值越大,延時(shí)越久
* 出口參數(shù):無(wú)
****************************************************************************/
void DelayNS(uint32 dly)
{ uint32 i;
for(; dly>0; dly--)
for(i=0; i<5000; i++);
}
// FLASH的起始地址(分配為Bank1塊)
#define FLASH_ADDR 0x81000000
// 轉(zhuǎn)換地址。將要發(fā)送給SST39VF160的地址值進(jìn)行轉(zhuǎn)換,以便于LPC2210輸出。
// 由于SST39VF160的A0是與LPC2210的A1相連,所以addr要左移1位。
#define GetAddr(addr) (volatile uint16 *)(FLASH_ADDR|(addr<<1))
/****************************************************************************
* 名稱:WordProgram()
* 功能:半字(16位)數(shù)據(jù)編程。
* 入口參數(shù):Addr 編程地址(SST39VF160內(nèi)部地址)
* Data 編程數(shù)據(jù)
* 出口參數(shù):返回TRUE表示操作成功,返回FALSE表示操作失敗
****************************************************************************/
uint8 WordProgram(uint32 Addr, uint16 Data)
{ volatile uint16 *ip;
uint16 temp1,temp2;
ip = GetAddr(0x5555); // 轉(zhuǎn)換地址0x5555
ip[0] = 0xaaaa; // 第一個(gè)寫周期,地址0x5555,數(shù)據(jù)0xAA
ip = GetAddr(0x2aaa);
ip[0] = 0x5555; // 第二個(gè)寫周期,地址0x2aaa,數(shù)據(jù)0x55
ip = GetAddr(0x5555);
ip[0] = 0xa0a0; // 第三個(gè)寫周期,地址0x5555,數(shù)據(jù)0xA0
ip = (volatile uint16 *)(FLASH_ADDR|(Addr&0x1FFFFF));
*ip = Data; // 第四個(gè)寫周期,地址Addr,數(shù)據(jù)Data
while (1) // 等待操作完成 (若編程操作沒有完成,每次讀操作DQ6會(huì)跳變)
{ temp1 = *ip;
temp2 = *ip;
if (temp1 == temp2)
{ if (temp1 != Data)
{ return(FALSE);
}
else
{ return(TRUE);
}
}
}
return(TRUE);
}
/****************************************************************************
* 名稱:ChipErase()
* 功能:芯片全片擦除。
* 入口參數(shù):無(wú)
* 出口參數(shù):返回TRUE表示操作成功,返回FALSE表示操作失敗
****************************************************************************/
uint8 ChipErase(void)
{ volatile uint16 *ip;
uint16 temp1,temp2;
ip = GetAddr(0x5555);
ip[0] = 0xaaaa; // 第一個(gè)寫周期,地址0x5555,數(shù)據(jù)0xAA
ip = GetAddr(0x2aaa);
ip[0] = 0x5555; // 第二個(gè)寫周期,地址0x2aaa,數(shù)據(jù)0x55
ip = GetAddr(0x5555);
ip[0] = 0x8080; // 第三個(gè)寫周期,地址0x5555,數(shù)據(jù)0x80
ip = GetAddr(0x5555);
ip[0] = 0xaaaa; // 第四個(gè)寫周期,地址0x5555,數(shù)據(jù)0xAA
ip = GetAddr(0x2aaa);
ip[0] = 0x5555; // 第五個(gè)寫周期,地址0x2aaa,數(shù)據(jù)0x55
ip = GetAddr(0x5555);
ip[0] = 0x1010; // 第六個(gè)寫周期,地址0x5555,數(shù)據(jù)0x10
while (1) // 等待操作完成 (若擦除操作沒有完成,每次讀操作DQ6會(huì)跳變)
{ temp1 = *ip;
temp2 = *ip;
if (temp1 == temp2)
{ if (temp1 != 0xffff)
{ return(FALSE);
}
else
{ return(TRUE);
}
}
}
return(TRUE);
}
/****************************************************************************
* 名稱:main()
* 功能:SST39VF160擦除、編程操作。
****************************************************************************/
int main(void)
{ uint8 i;
uint8 err = 0;
volatile uint16 *addr;
PINSEL0 = 0x00000000; // 設(shè)置管腳連接GPIO
IO0DIR = BEEPCON; // 設(shè)置I/O為輸出
ChipErase(); // FLASH全片擦除
// 校驗(yàn)是否真正擦除。若發(fā)現(xiàn)有非0xFFFF的存儲(chǔ)單元,設(shè)置err=1
addr = (volatile uint16 *)FLASH_ADDR + 0;
for(i=0; i<100; i++)
{ if(0xFFFF != (*addr)) err = 1;
addr++;
}
WordProgram(0x0, 0x55AA); // 向FLASH的0地址寫入0x55AA
addr = (volatile uint16 *)FLASH_ADDR + 0;
if(0x55AA != (*addr)) err = 1; // 讀出校驗(yàn),若數(shù)據(jù)錯(cuò)誤則設(shè)置err=1
if(0==err)
{ IO0CLR = BEEPCON; // BEEPCON = 0
DelayNS(20);
IO0SET = BEEPCON; // BEEPCON = 1
DelayNS(20);
}
else
{ while(1)
{ IO0CLR = BEEPCON; // BEEPCON = 0
DelayNS(10);
IO0SET = BEEPCON; // BEEPCON = 1
DelayNS(10);
}
}
while(1);
return(0);
}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -