打印
[技术问题解答]

dz60的eeprom问题

[复制链接]
1652|4
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
cl234583745|  楼主 | 2015-1-8 10:23 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
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);
}


HCS08EEPROM.zip

790.39 KB

相关帖子

沙发
FSL_TICS_ZJJ| | 2015-1-8 10:59 | 只看该作者
楼主,你芯片自带的EEPROM大小多少?
不要用出界。

使用特权

评论回复
板凳
cl234583745|  楼主 | 2015-1-8 11:07 | 只看该作者
本帖最后由 cl234583745 于 2015-1-8 11:41 编辑
FSL_TICS_ZJJ 发表于 2015-1-8 10:59
楼主,你芯片自带的EEPROM大小多少?
不要用出界。

2k,早的呢?上面的读写函数里面改动下就能行,什么起始地址什么页面的。不知道怎么回事。
真后悔开始时候没有弄会pe,现在都是自己写,不会用pe


上面写的函数,是不是每次写,都吧后面的擦除了呢?我复制了一个写函数,只是把起始地址+255了。原来的255的字节好使,后面总是被清空。单独执行我复制的写函数还是好使的。

使用特权

评论回复
地板
FSL_TICS_ZJJ| | 2015-1-8 13:49 | 只看该作者
cl234583745 发表于 2015-1-8 11:07
2k,早的呢?上面的读写函数里面改动下就能行,什么起始地址什么页面的。不知道怎么回事。
真后悔开始时候 ...

EEPROM在写之前,要求先擦除相关字,然后再写入。
如果前面256个字节的写,或导致后面的地址被清空,你进去看看你的擦除函数,到底擦掉哪些地址?

使用特权

评论回复
5
sunriselight| | 2015-1-27 14:11 | 只看该作者
下载器设置每次自动擦除了么?

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

99

主题

644

帖子

1

粉丝