dz60的eeprom问题。cw6.3版本(仿真界面不能观看eeprom里面每个位置的数据吗)
我是参考这个附件里面的做的。之前是好使的,虽然我不明白具体怎么回事。但后来要保存的数据超过255字节了,那个读写函数最大能写255,uchar型的。请问该怎么改写一下呢?
(其实我也不清楚为啥这里的起始地址和页面大小和用pe生成的代码里面都不同。pe弄的没有弄好使,根据这个函数弄得好使了,只是现在数据超过255了,不知道怎么改了)
/**
** EEPROM data is treated as fixed-size record.
** FLAG, DATA0, DATA1, DATA2, ..., DATAn
**
**/
#define EEPROM_DATA_LEN 255
/**
** Refer to the PRM file of your project and define HCS08_FLASH_START_ADDR
** accordingly. Also the PRM file should be modified to specify the new ROM
** address. 2 pages are used for EEPROM emulatio, thus ROM = ROM + 0x200.
**/
#define HCS08_FLASH_START_ADDR 0xE000
/**
** Page size of HCS08 is 0x200
**/
#define HCS08_FLASH_PAGE_SIZE 0x200
/**
** CPU bus frequncy, modify it according to your system configuration.
** Unit is kHz. For example, 4 MHz is defined as 4000 (kHz)
**/
#define HCS08_BUS_FREQUENCY 4000 //这里我也不懂是什么,我的总线频率24m,这里我没有修改也是好使的
/**
** FLASH block protection. Default is off.
** It is stongly to turn it on to protect the code space of CPU.
**/
#define HCS08_FLASH_PROTECTION 0xFF
** ===================================================================
** Method : HCS08_EE_WriteRecord
**
** Description :
** this function writes the whold data record to the next
** available space block of FLASH, also the Record Has Been
** used flag before the data. If the current page will be full,
** it erases the next page.
** Patameters:
** unsigned char *. -- point to the source data
** Return Values:
** status
** ===================================================================
*/
unsigned char HCS08_EE_WriteRecord(unsigned char *src)
{
unsigned int i, j;
unsigned char flag_page_switch;
unsigned int ee_current_page, ee_next_page;
flag_page_switch = 0;
ee_current_page = EEPROM_START_ADDR;
ee_next_page = EEPROM_START_ADDR + EEPROM_PAGE_SIZE;
// find the current page
if (FLAG_CURENT_PAGE !=
flash_byte_read(ee_current_page + EEPROM_PAGE_SIZE - 1))
{
ee_current_page = EEPROM_START_ADDR + EEPROM_PAGE_SIZE;
ee_next_page = EEPROM_START_ADDR;
}
for (;;)
{
for (i = 0;
i < PAGE_REUSE_TIMES * EEPROM_DATA_LEN;
i = i + EEPROM_DATA_LEN + 1)
{
if (FLAG_RECORD_USED != flash_byte_read(ee_current_page + i))
{
// this record space is empty
// wite flag to mark this record is used
flash_byte_prog(ee_current_page + i, FLAG_RECORD_USED);
// then write the record data to the following addresses
for (j = 0; j < EEPROM_DATA_LEN; j++)
{
flash_byte_prog(ee_current_page + 1 + i + j, *(src + j));
}
// do we need to switch to next page?
if (flag_page_switch)
flash_page_erase(ee_next_page);
return HCS08_EE_ERROR_OK;
}
}
// all the records are visited now, but does not find the current record
// page switch
j = ee_next_page;
ee_next_page = ee_current_page;
ee_current_page = j;
flag_page_switch = 1;
// mark the current page
flash_byte_prog((ee_current_page + EEPROM_PAGE_SIZE -1), FLAG_CURENT_PAGE);
}
}
/*
** ===================================================================
** Method : HCS08_EE_ReadRecord
**
** Description :
** this function finds the current record in the current page,
** then reads the all the data in the record to a buffer.
** Patameters:
** unsigned char *. -- point to the dest buffer
** Return Values:
** status
** ===================================================================
*/
unsigned char HCS08_EE_ReadRecord(unsigned char *dest)
{
unsigned int i, j;
unsigned int ee_current_page;
ee_current_page = EEPROM_START_ADDR;
// find the current page
if (FLAG_CURENT_PAGE != flash_byte_read(ee_current_page + EEPROM_PAGE_SIZE - 1))
ee_current_page = EEPROM_START_ADDR + EEPROM_PAGE_SIZE;
// visit all the records till find out the 'current' record
for (i = 0;
i < (PAGE_REUSE_TIMES - 1) * EEPROM_DATA_LEN;
i+= EEPROM_DATA_LEN + 1)
{
if (FLAG_RECORD_USED != flash_byte_read(ee_current_page + 1 + i + EEPROM_DATA_LEN))
break;
}
// when the 'current' record is found, read data of it
for (j = 0; j < EEPROM_DATA_LEN; j++)
*(dest + j) = flash_byte_read(ee_current_page + 1 + i + j);
return HCS08_EE_ERROR_OK;
}
uchar JS[255];、、、、、、、、、、、、、、、、、、、、、、如果有另一个数组怎么读写呢?
//参数写入EEPROM/////////////////////////////////////////////////////////////////////////////////
void W_CS(void)
{
ERROR_OK=HCS08_EE_WriteRecord(JS);
}
//参数写入EEPROM/////////////////////////////////////////////////////////////////////////////////
void R_CS(void)
{
ERROR_OK=HCS08_EE_ReadRecord(JS);
}
|