📄 rx2flash.c.bak
字号:
/* rx2flash.c */
//#include<reg51rd2.h>
#include"types.h"
#include"c51rx2.h"
#include"reg52.h"
#include"stimer.h"
#ifdef WATCHDOG
#define CLRWDT
#endif
#define _pusha() ;
#define _popa() ;
#ifndef _pusha
void _pusha(void);
void _popa(void);
#endif
/********************************************
* FlashFlex51 MCU SFR Memory Addresses
*********************************************/
sfr SFCF = 0xB1; /*SuperFlash Configuration*/
sfr SFCM = 0xB2; /*SuperFlash Command*/
sfr SFAL = 0xB3; /*SuperFlash Address Low*/
sfr SFAH = 0xB4; /*SuperFlash Address High*/
sfr SFDT = 0xB5; /*SuperFlash Data*/
sfr SFST = 0xB6; /*SuperFlash Status*/
/********************************************
* FlashFlex51 MCU IAP Commands
*********************************************/
#define SFCM_SE 0x0B; /*Sector-Erase IAP cmd*/
#define SFCM_VB 0x0C; /*Byte-Verify IAP cmd*/
#define SFCM_PB 0x0E; /*Byte-Program IAP cmd*/
/********************************************
* Global Variable Definition
*********************************************/
const unsigned short int BLK1_DST_ADDR = 0x1000;
/*SST89x564RD destination address (in the other on-chip flash memory block)
where data will be written to, which is above BSL code space.*/
const unsigned char SECT_SIZE = 0x80; /*number of bytes in a sector*/
// test if operation is ready
bool ready()
{
unsigned long int TimeOut = 0;
while (TimeOut < 100000)
{
if ((SFST&4) == 0) /* Check if IAP is done */
{ /* IAP is done */
SFCF = SFCF & 0xBF; /* turn off IAP*/
SFDT = 0; /* any value other than 0x55 */
return true; /* IAP operation is completed*/
}
GetTickCount();
}
SFCF = SFCF & 0xBF; /*turn off IAP*/
SFDT = 0; /*any value other than 0x55*/
return false; /*IAP operation is NOT completed before time out*/
}
// write a byte to flash
bool FlashWrByte(uint addr, uchar ch)
{
disable();
SFCF = SFCF | 0x40; /*enable IAP */
SFAH = addr>>8; /*load high order address byte*/
SFAL = addr & 0xff; /*load low order address byte */
SFDT = ch; /*load data to be programmed */
SFCM = SFCM_PB; /*issue byte program command */
if(!ready())
{
enable();
return false;
}
enable();
return true;
}
// erase sector
// addr: 00h, 80h
bool FlashErSector(uint addr)
{
disable();
SFCF = SFCF | 0x40; /*enable IAP */
SFAH = addr>>8; /*load high order address byte*/
SFAL = addr & 0xff; /*load low order address byte */
SFCM = SFCM_SE; /*issue sector erase command */
if(!ready())
{
enable();
return false;
}
enable();
return true;
}
// read device data
uchar FlashRdByte(uint addr)
{
unsigned char readByte;
disable();
SFCF = SFCF | 0x40; /*enable IAP */
SFAH = addr>>8; /*load high order address byte*/
SFAL = addr & 0xff; /*load low order address byte */
SFCM = SFCM_VB; /*issue byte verify command */
readByte = SFDT;
SFCF = SFCF & 0xBF; /*turn off IAP*/
SFDT = 0;
enable();
return readByte;
}
#if 0
void ErBlock0(void)
{
SFCF = SFCF | 0x40;
SFAH =
SFAL =
SFDT = 0x55;
SFCM = 0x0d;
}
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -