首页 | 新闻 | 新品 | 文库 | 方案 | 视频 | 下载 | 商城 | 开发板 | 数据中心 | 座谈新版 | 培训 | 工具 | 博客 | 论坛 | 百科 | GEC | 活动 | 主题月 | 电子展
返回列表 回复 发帖

[求助]用C语言如何编写MC9S12DG128的EEPROM檫除,写入程序

[求助]用C语言如何编写MC9S12DG128的EEPROM檫除,写入程序

我在参照《单片机嵌入式系统在线开发方法》一书中的MC9S12DG128单片机EEPROM
操作列程编写程序,结果是写入地址的数据掉电不能保持。好象400  到FFF不是EEPROM
地址,请问是地址的问题还是程序有问题。[em13]
fgfgf
EEPROM的具体地址由INITEE寄存器控制。请参见《S12MMCV4.pdf》文件中关于INITEE的介绍。
海纳百川  有容乃大
你的问题我调试的时候碰到过,但现在解决了。是你的寄存器配置的问题。
水泡泡
 我的QQ是:52449804 
 我的网站是: www.dyic.com.cn
 欢迎访问和留言跟我联系
楼上的朋友,我用的是CODEWARRIOR 生成的工程,把《单片机嵌入式系统在线开发方法》一书中的MC9S12DG128单片机EEPROM操作列程完全照班结果是掉电后数据丢失。INITEE=0X01,MEMSIZ0-EEP-SW0=1,MEMSIZ0-EEP-SW1=1,配置。ECLKDIV=49,(16M晶振),请问到底怎样配置寄存器呢,十万火急。能给个例程吗。
fgfgf
有例程啊,我的Email是nishui_2000@163.com,你的是什么告诉我先啊,我发给你的例程肯定好用。在9S12D64上用没任何问题。但我也要问你几个问题你要告诉我先:1,你的晶振用的是有源还是无源晶振,如果是无源怎么连接的?是不是买的普通那种两脚的晶振,我用的两个脚的怎么振不起来呢。 2,你用过以太网么,如果不要25M晶振,那怎么改个别寄存器,我改了半天都Ping不通,只能用25M。 3,看看我的网站,www.dyic.com.cn ,上面有我的联系方式
水泡泡
 我的QQ是:52449804 
 我的网站是: www.dyic.com.cn
 欢迎访问和留言跟我联系
/******************************************************************* * EEPROM program command subroutine * Description : Copy from RAM area to EEPROM area * : Input RAM,EEPROM start address and no. of word to be * : programmed * Example : Copy 4 words from RAM(0x1000) to EEPROM (0x600) * input : eram_addi=0x1000, eeprom_addi=0x600, no_of word=0x4 * modify : eeprom content (0x600 to 0x608)= (0x1000 to 0x1008) *********************************************************************/ void eeprom_program_cmd(int eram_addi, int eeprom_addi, int no_of_word) { int *ram_add,*eeprom_add,count=0; ram_add=(int*)eram_addi; eeprom_add=(int*)eeprom_addi; eclkdiv = 0x49; DisableInterrupts; estat=pviol+accerr; //movb #$30,$115 ; clear previous command error while(count!=no_of_word) { *eeprom_add=*ram_add; //; get data and put it to EEPROM ecmd=prog; //; initiate PROGRAM COMMAND estat=cbeif; //; begin command if(((estat&pviol)==pviol)||((estat&accerr)==accerr)) printf0("EEprom programming error\n\r"); //display eree_program_error else while((estat&ccif)==0x00); // wait for command to complete count++; eeprom_add++; ram_add++; } EnableInterrupts; } /******************************************************************* * EEPROM erase command subroutine * Description : Erase EEPROM long word (4 bytes) * : Input EEPROM start address and no. of word to be * : erased * Example : Erase 4 long words from EEPROM (0x600) * input : eeprom_addi=0x600, no_of word=0x4 * modify : eeprom content (0x600-0x610)=0xff *********************************************************************/ void eeprom_erase_cmd(int eeprom_addi, int no_of_long_word) { int *eeprom_add,count=0; eeprom_add=(int*)eeprom_addi; eclkdiv = 0x49; DisableInterrupts; estat=pviol+accerr; //movb #$30,$115 ; clear previous command error while(count!= no_of_long_word) { *eeprom_add=0; // to erase the data at EEPROM ecmd=erase; //; initiate ERASE COMMAND estat=cbeif; //; begin command if(((estat&pviol)==pviol)||((estat&accerr)==accerr)) { printf0("EEprom programming error in \n\r"); //display eree_program_error hex_asc((byte)(eeprom_addi>>8)); hex_asc((byte)(eeprom_addi)); printf0("\n\r"); //display lf } else while((estat&ccif)==0x00); // wait for command to complete count++; eeprom_add+=2; //int pointer increment eeprom_addi+=4; //eeprom_addi increment by 4 (long) tx_char0('.'); } EnableInterrupts; } /******************************************************************* * EEPROM program subroutine * Description : User input RAM area and EEPROM area to be copied * : Input RAM,EEPROM start address and no. of word to be * : programmed * Example : Copy 4 words from RAM(0x1000) to EEPROM (0x600) * input : eram_addi=0x1000, eeprom_addi=0x600, no_of word=0x4 * modify : eeprom content *********************************************************************/ void eeprom_program() { unsigned int *eeprom_addi,add0,*eram_addi,add1; byte status=DISABLE,ebyte; eeprom_addi=&add0; eram_addi=&add1; printf0("RAM start address (0x1000-0x12ff)= \r"); if(input_word(eram_addi)==OK) { if((*eram_addi>=0x1000)&&(*eram_addi<0x1300)) status=ENABLE; else { printf0("\nOut of range!\r"); status=DISABLE; } } else status=DISABLE; printf0("\n\r"); if (status==ENABLE) { printf0("EEPROM start address to be programmed ($400 default)= \r"); if(input_word(eeprom_addi)==OK) { if((*eeprom_addi>=0x400)&&(*eeprom_addi<0x1000)) status=ENABLE; else { printf0("\nOut of range!\r"); status=DISABLE; } } else status=DISABLE; printf0("\n\r"); } if (status==ENABLE) { printf0("No. of word to be programmed (Dec) = \r"); if(input_dec(&ebyte)==OK) { if (((ebyte)==DOT)||((ebyte)==ESC)) status=DISABLE; else status=ENABLE; printf0("\n\r"); } } if (status==ENABLE) eeprom_program_cmd(*eram_addi, *eeprom_addi, (unsigned int) ebyte); } /******************************************************************* * EEPROM erase subroutine * Description : Erase EEPROM long word (4 bytes) * : User input EEPROM start address and no. of word to be * : erased * Example : Erase 4 long words from EEPROM (0x600) * input : eeprom_addi=0x600, no_of word=0x4 * modify : eeprom content (0x600-0x610)=0xff *********************************************************************/ void eeprom_erase() { unsigned int *address,add; byte status=DISABLE,ebyte; address=&add; printf0("EEPROM start address to be Erase (hex) (0x400-0xfff) = \r"); if(input_word(address)==OK) { if((*address>=0x400)&&(*address<0x1000)) status=ENABLE; else { printf0("\nOut of range!\r"); status=DISABLE; } } else status=DISABLE; printf0("\n\r"); if (status==ENABLE) { printf0("No. of long word (4 bytes) to be erased (Dec) = \r"); if(input_dec(&ebyte)==OK) { if (((ebyte)==DOT)||((ebyte)==ESC)) status=DISABLE; else status=ENABLE; printf0("\n\r"); } } if (status==ENABLE) eeprom_erase_cmd(*address, (unsigned int) ebyte); }
谢谢大家的帮助,我的MC9S12DG128的EEPROM程序已调试通了,其实程序没错
是EEPROM的地址不对,我的工程是在COLDWARROR上生成的,在PE下,EEPROM
被定义到2000——3FFF,设置INITEE=0X27;MISC =1;eclkdiv = 0x49;结果程序
运行正确了,告知大家!
fgfgf
返回列表