📄 flash.c
字号:
#include "REG51F.H"
#include "flash.h"
#include "string.h"
#include "stdio.h"
#include "intrins.h"
/***********************************************************************
* Function name : Flash_Sector_Erase *
* Input : unsigned char, (Sector number selected) *
* Output : bit, (0->operation fail, 1->operation successful) *
* Description : This function will perform a sector erase on the *
* sector number (sec_no) of the selected (CS) flash *
* memory device. 1 sector is 64Kbytes The operation will *
* roughly take 2 seconds for 1 sector. All paging to the *
* CPLD is done in this function. *
* Caution! ; Do not perform this operation on program flash memory *
* while running program on the program flash. *
************************************************************************/
bit Flash_Sector_Erase (unsigned char data sec_no)
{
unsigned int data addr;
addr=(unsigned int )sec_no*512;
ISPFD=0X55;
ISPFD=0XAA;
ISPFD=0X55;
SCONF=0X04; //OPEN ISP
ISPFAH=(addr&0xFF00)>>8;
ISPFAL=addr&0x00ff;
ISPC=0XA2;
return 1;
}
/************************************************************************
* Function name : Flash_Write *
* Input : union ADDRESS, (32bit address location) *
* unsigned char, (Data to be written *
* Output : bit, (0->operation fail, 1->operation successful) *
* Description : This function will perform a prgramming on the *
* selected (CS) flash memory device. 1 byte of data is *
* being written to the location (Address). All paging to *
* the CPLD is done in this function. *
* Caution! ; Make sure the location to be program is eraseed (0xFF) *
* before calling this function *
* Do not perform this operation on program flash memory *
* while running program on the program flash. *
************************************************************************/
bit Flash_Write (unsigned int Address, unsigned char data *_data,unsigned char data len)
{
unsigned char data i;
ISPFD=0X55;
ISPFD=0XAA;
ISPFD=0X55;
SCONF=0X04; //OPEN ISP
ISPFAH=Address>>8;
ISPFAL= Address;
ISPFD=*_data;
ISPC=0XA0;
for(i=0;i<len;i++)
{
ISPFAH=Address>>8;
ISPFAL= Address;
ISPFD=*_data;
ISPC=0XA0;
Address++;
_data++;
}
return 1;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -