打印

请教关于PIC单片机写EEPROM上电默认值的问题

[复制链接]
5222|5
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
soso|  楼主 | 2007-12-8 15:01 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
  我用PIC单片机(内含EEPROM)做的产品,上电后第一件事是先从EEPROM中读出定值,我现在的做法是先把写EEPROM的子函数(写默认值)加到程序里,下载程序之后,上电运行,然后再把写EEPROM的子函数屏蔽掉,重新写程序。是否有简便的办法,好像汇编中可以直接写EEPROM的值,以后再重新上电就不会再重新EEPROM的值,请大虾指点下。
  
沙发
幸福DE饭团| | 2007-12-8 15:12 | 只看该作者

直接用烧写器烧写EEPROM的内容,连写EEPROM的子函数都省了

使用特权

评论回复
板凳
xieyuanbin| | 2007-12-9 19:51 | 只看该作者

可在EEPROM中预先定义一个数组


int _EEDATA(2) USER_DATA[16] = {};
或:
int _EEDATA(2) USER_DATA[16] = {1,2,3};

使用特权

评论回复
地板
sosomj| | 2007-12-13 10:08 | 只看该作者

回复

PICC中的写法:

// 0x00 - 0x0f    
__EEPROM_DATA (0x55,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa);
__EEPROM_DATA (0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa);
// 0x10 - 0x1f
__EEPROM_DATA (0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa);
__EEPROM_DATA (0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa);    
// 0x20 - 0x2f
__EEPROM_DATA (0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa);
__EEPROM_DATA (0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa);        
// 0x30 - 0x3f
__EEPROM_DATA (0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa);
__EEPROM_DATA (0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa);        
// 0x40 - 0x4f
__EEPROM_DATA (0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa);
__EEPROM_DATA (0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa);        
// 0x50 - 0x5f
__EEPROM_DATA (0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa);
__EEPROM_DATA (0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa);        
// 0x60 - 0x6f
__EEPROM_DATA (0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa);
__EEPROM_DATA (0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa);            
// 0x70 - 0x7f
__EEPROM_DATA (0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00);
__EEPROM_DATA (0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00);    
// 0x80 - 0x8f
__EEPROM_DATA (0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00);
__EEPROM_DATA (0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00);
// 0x90 - 0x9f
__EEPROM_DATA (0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00);
__EEPROM_DATA (0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00);
// 0xa0 - 0xaf
__EEPROM_DATA (0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00);
__EEPROM_DATA (0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00);
// 0xb0 - 0xbf
__EEPROM_DATA (0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00);
__EEPROM_DATA (0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00);
// 0xc0 - 0xcf
__EEPROM_DATA (0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00);
__EEPROM_DATA (0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00);
// 0xd0 - 0xdf
__EEPROM_DATA (0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00);
__EEPROM_DATA (0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00);
// 0xe0 - 0xef
__EEPROM_DATA (0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00);
__EEPROM_DATA (0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00);
// 0xf0 - 0xff
__EEPROM_DATA (0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00);
__EEPROM_DATA (0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00);

汇编的写法:
    org    0x2100

; 0x00 - 0x0f    
    de    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
; 0x10 - 0x1f
    de    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00    
; 0x20 - 0x2f
    de    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00    
; 0x30 - 0x3f
    de    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00    
; 0x40 - 0x4f
    de    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00    
; 0x50 - 0x5f
    de    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00    
; 0x60 - 0x6f
    de    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00    
; 0x70 - 0x7f
    de    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
; 0x80 - 0x8f
    de    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
; 0x90 - 0x9f
    de    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
; 0xa0 - 0xaf
    de    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
; 0xb0 - 0xbf
    de    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
; 0xc0 - 0xcf
    de    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
; 0xd0 - 0xdf
    de    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
; 0xe0 - 0xef
    de    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
; 0xf0 - 0xff
    de    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00

使用特权

评论回复
5
euvjin| | 2007-12-14 16:35 | 只看该作者

做个标志嘛

做个标志,上电时从eeprom读出标志:如果第一次使用,标志不正确,写默认值并且写标志;如果标志正确就读定值

使用特权

评论回复
6
soso|  楼主 | 2007-12-15 10:03 | 只看该作者

谢谢各位大哥指点

   谢谢各位大哥这么详细的指点,我现在采用4楼做法。

使用特权

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

本版积分规则

0

主题

0

帖子

1

粉丝