新聞中心

EEPW首頁 > 嵌入式系統(tǒng) > 設計應用 > C8051F12X操作FLASH存儲器程序

C8051F12X操作FLASH存儲器程序

作者: 時間:2016-11-30 來源:網絡 收藏
DBMODE 為數(shù)據線的輸入輸出模式 為單片機的PXMDOUT
DBOUT 為輸出模式
DBus 為數(shù)據端口 Px
/--------FLASH命令傳送------//
void Comm_Latch_Cycle(uchar COMMAND)
{
uchar SFRPAGE_SAVE = SFRPAGE;
SFRPAGE = CONFIG_PAGE;
DBMODE = DBOUT;
ALE=0;
ALE=0;
CLE=1;
RE=1;
WE=1;
DBus=COMMAND; //WRITE COMMAND
WE=0;
WE=1;
CLE=0;
ALE=0;
SFRPAGE = SFRPAGE_SAVE;

}
//------------------ 傳送地址------------------------------
void Add_Latch_Cycle(uint ADDR ) //傳送地址,ADDR為頁地址,從addr頁第0字節(jié)開始
{
uchar SFRPAGE_SAVE = SFRPAGE;
SFRPAGE = CONFIG_PAGE;
DBMODE= DBOUT;
CLE=0;
ALE=1;
RE=1;
WE=1;
DBus=0; //A0-A7,column address
WE=0;
WE=1;
DBus=(uchar)ADDR; //A9-A16 ,Row Address page address A12-A29
WE=0;
WE=1;
DBus=(uchar)(ADDR>>8); //A17-A24,Row Address
WE=0;
WE=1;
ALE=0;
CLE=0;
SFRPAGE = SFRPAGE_SAVE;
}
//讀狀態(tài),狀態(tài)正確時返回0,錯誤時返回1
uchar Status_Read(void)
{
uchar Status;
Comm_Latch_Cycle(0x70);
Status=Read_Byte();
Status=Status & 0x01;
return Status; //status=0 erease ok else failled
}
//從FLASH讀一個字節(jié)
uchar Read_Byte(void) //read one bytefromflash
{
uchar Rdata;
char SFRPAGE_SAVE = SFRPAGE;
SFRPGCN=CONFIG_PAGE;
DBMODE = DBIN; //Data Bus input mode
DBus = 0xFF;
ALE =0;
CLE =0;
RE =1;
RE =0;
Rdata =DBus;
RE=1;
SFRPAGE = SFRPAGE_SAVE;
return(Rdata);
}
//------------------Block Erease------------------------------
uchar Block_Erase(uint page_number) //
{
uchar SFRPAGE_SAVE = SFRPAGE;
SFRPAGE = CONFIG_PAGE;
DBMODE= DBOUT;
Comm_Latch_Cycle(0x60);
ALE=1;
CLE=0;
DBus=(uchar)page_number; //A9-A16
WE=0;
WE=1;
DBus=(uchar)(page_number>>8); //A17-A24
WE=0;
WE=1;
ALE=0;
CLE=0;
Comm_Latch_Cycle(0xD0);
SFRPAGE = CONFIG_PAGE;
RB = 1;
while(!RB);
SFRPAGE=SFRPAGE_SAVE;
return Status_Read(); //status=1,Bad Block; Status = 0, Erease OK
}


關鍵詞: C8051F12XFLASH存儲

評論


技術專區(qū)

關閉