怎样读写AVR的EEPROM

[复制链接]
 楼主| yzgln 发表于 2009-1-8 14:28 | 显示全部楼层 |阅读模式
我用了一个ATMEGA128的芯片,现无法操作EEPROM,我的程序如下,请大侠看看是那儿出了问题.
;**************read eeprom*******************
readee:
    cli                    ;关中断
    ldi r25,0x00
    ldi r24,0x00
    ldi xh,high(hddatehd);预置缓存地址
    ldi xl,low(hddatehd)
    ldi temp1,0x0b        ;置循环数
readee2:
    sbic eecr,eewe        ;等待EEWE位变零
    rjmp readee2
    out eearh,r25
    out eearl,r24        ;预置EEPROM地址
    sbi eecr,eere        ;置EERE位有效
    in temp3,eedr        ;读出数据
    st x+,temp3            ;将数据存入缓冲
    adiw r24,0x01        ;将EEPROM地址加1
    dec temp1            ;将循环数减1
;    cpi temp1,0x00
    brne readee2        ;读出所有的数据,共11个字节
    sei                    ;开中断
    ret
;**************write eeprom*******************
writee:
    cli            ;;关中断
    ldi r25,0x00    
         ldi r24,0x00
    ldi xh,high(hddatehd);预置缓存地址
    ldi xl,low(hddatehd)
    ldi temp1,0x0b        ;置循环数
writee1:
    ldi temp2,0x0f
    call yanshi            ;调用延时程序,20ms
writee2:
    sbic eecr,eewe        ;等待EEWE位变零
    rjmp writee2
    out eearh,r25
    out eearl,r24        ;预置EEPROM地址
    ld temp3,x+
    out eedr,temp3        ;准备写入的数据
    ldi temp4,0b00000100;eemwe置1,并同时清eewe为0
    ldi temp5,0b00000110;置位写允许位,将数据写入EEPROM
    out eecr,temp4;    ;置位主机写入允许位
    out eecr,temp5;    ;置位写允许位,将数据写入EEPROM
    adiw r24,0x01        ;将EEPROM地址加1
    dec temp1            ;将循环数减1
;    cpi temp1,0x00
    brne readee1        ;写入所有的数据,共11个字节
    sei
    ret
古道热肠 发表于 2009-1-9 13:55 | 显示全部楼层

用C语言吧

很简单的函数调用就行了.
救火车 发表于 2009-1-9 18:48 | 显示全部楼层

多年以前我写过汇编的程序。

可是太烂了,不敢拿出来见人。
古道肠说得对,你还是用C语言吧。
hotpower 发表于 2009-1-9 20:23 | 显示全部楼层

winavr的EEPROM函数非常好用,很安全

您需要登录后才可以回帖 登录 | 注册

本版积分规则

8

主题

13

帖子

0

粉丝
快速回复 在线客服 返回列表 返回顶部

8

主题

13

帖子

0

粉丝
快速回复 在线客服 返回列表 返回顶部