📄 resetcounter.bak
字号:
#include <stdio.h>
#include <reg1210.h>
#include "rom1210.h"
// define the page we want to modify
#define PAGE_START 0x0400
#define PAGE_SIZE 0x80
// define a pointer to this page
char xdata * pFlashPage;
// define a RAM area as a buffer to hold one page
char xdata Buffer[PAGE_SIZE];
int main()
{
char Result;
unsigned char i;
pFlashPage = (char xdata * ) PAGE_START;
// before writing the flash, we have to initialize
// the usec and msec SFRs because the flash programming
// routines rely on these SFRs
USEC = 12-1; // assume a 12 MHz clock
MSEC = 12000-1;
// copy the page from FLASH to RAM
for(i=0;i<PAGE_SIZE;i++)
Buffer[i] = *pFlashPage++;
// increment the counter
Buffer[0] += 1;
// now erase the page
page_erase(PAGE_START, 0xff, DATA_FLASH);
Result = 0;
// and write the modified contents back into flash
for(i=0;i<PAGE_SIZE;i++)
Result |= write_flash_chk (PAGE_START+i, Buffer[i], DATA_FLASH);
// synchronize baud rate
autobaud();
printf("Writing flash returned %d\n", (int)Result);
// re-read the counter
pFlashPage = (char xdata *) PAGE_START;
printf("Reset counter is now %d\n", (int)(*pFlashPage));
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -