写入EEPROM的PIC [英] Writing to EEPROM on PIC

查看:301
本文介绍了写入EEPROM的PIC的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有任何PIC单片机的程序员在这里?

我正在学习用PICKIT2和附带的16F690芯片的一些PIC单片机编程。我通过目前试行的各种设施的工作。我可以成功地阅读从code中的EEPROM,如果我设置MPLAB EEPROM中vaklue,但我似乎不能够修改使用PIC itsself值的字节。简单地什么也没发生,我不读回修改的值,我总是得到这意味着我原来那个写不工作?

这是我的code该节,我失去的东西吗?我知道我在做了很多不必要的银行开关,我加入他们大多以确保正对错误的银行是不是问题。

 ; -------------------------------------------------- ----
        ;现在设置的EEPROM存储单元零至0×08
        ; -------------------------------------------------- ----        BANKSEL EEADR
        CLRF EEADR;设置EE地址为零        BANKSEL EEDAT
        MOVLW 0x08的;存储值0x08的EEPROM中
        MOVWF EEDAT        BANKSEL EECON1
        BSF EECON1,雷恩;使能写入EEPROM        BANKSEL EECON2
        MOVLW将0x55;做的事,我们不得不这样做
        MOVWF EECON2;这写可以工作
        MOVLW和0xAA
        MOVWF EECON2        BANKSEL EECON1
        BSF EECON1,WR;最后进行写入等待
        BTFSC EECON1,WR;等待写入完成
        GOTO WAIT        BANKSEL PORTC;只是为了确保我们在右岸


解决方案

16F690数据表,它详细介绍写入EEPROM的正确方法:


  BANKSEL EEADR;
MOVF DATA_EE_ADDR,W;
MOVWF EEADR;数据存储器地址写
MOVF DATA_EE_DATA,W;
MOVWF EEDAT;数据存储器要写入的值
BANKSEL EECON1;
BCF EECON1,EEPGD;点数据存储器
BSF EECON1,雷恩;启用写入
BCF INTCON,GIE;禁止INT的。
BTFSC INTCON,GIE;查阅AN576
GOTO $ -2
; BEGIN要求的顺序
MOVLW 55H;
MOVWF EECON2; 55h写入
MOVLW将AAh;
MOVWF EECON2;将AAh
BSF EECON1,WR;将WR位置开始写
BSF INTCON,GIE;允许INT的。
睡眠;等待中断信号写完成
; END所需的顺序
BCF EECON1,雷恩;禁止写入
BANKSEL为0x00;银行0


我注意到,你是专门缺少这一行:

  BCF EECON1,EEPGD;点数据存储器

如果 EEPGD 总是设置,那么你就试着写程序存储器(又名覆盖闪存程序存储器)应该始终失败,除非你出去你的方式来专门启用。

除此之外,据我可以阅读您的code告诉,一切看起来不错。这没关系,你是轮询 EECON1.​​WR 而不是设置中断。这将花费你更多的权力不是将设备的睡眠,当然你只应该在一个时间操心的一件事。

Are there any PIC microcontroller programmers here?

I'm learning some PIC microcontroller programming using a pickit2 and the 16F690 chip that came with it. I'm working through trying out the various facilities at the moment. I can sucessfully read a byte from the EEPROM in code if I set the EEPROM vaklue in MPLAB but I don't seem to be able to modify the value using the PIC itsself. Simply nothing happens and I don't read back the modified value, I always get the original which implies to me that the write isn't working?

This is my code for that section, am I missing something? I know I'm doing a lot of unnecessary bank switches, I added most of them to ensure that being on the wrong bank wasn't the issue.

        ; ------------------------------------------------------
        ; Now SET the EEPROM location ZERO to 0x08
        ; ------------------------------------------------------

        BANKSEL EEADR
        CLRF    EEADR           ; Set EE Address to zero

        BANKSEL EEDAT
        MOVLW   0x08            ; Store the value 0x08 in the EEPROM
        MOVWF   EEDAT

        BANKSEL EECON1
        BSF     EECON1, WREN    ; Enable writes to the EEPROM

        BANKSEL EECON2
        MOVLW   0x55            ; Do the thing we have to do so
        MOVWF   EECON2          ; that writes can work
        MOVLW   0xAA
        MOVWF   EECON2

        BANKSEL EECON1      
        BSF     EECON1, WR      ; And finally perform the write

WAIT
        BTFSC   EECON1, WR      ; Wait for write to finish
        GOTO    WAIT

        BANKSEL PORTC           ; Just to make sure we are on the right bank

解决方案

On page 122 of the 16F690 datasheet, it details the proper way to write to EEPROM:

BANKSEL EEADR                   ;
MOVF    DATA_EE_ADDR, W;
MOVWF   EEADR          ;Data Memory Address to write
MOVF    DATA_EE_DATA, W;
MOVWF   EEDAT                   ;Data Memory Value to write
BANKSEL EECON1                  ;
BCF     EECON1, EEPGD ;Point to DATA memory
BSF     EECON1, WREN   ;Enable writes
BCF     INTCON, GIE             ;Disable INTs.
BTFSC   INTCON, GIE             ;SEE AN576
GOTO    $-2
; BEGIN REQUIRED SEQUENCE
MOVLW   55h            ;       
MOVWF   EECON2         ;Write 55h
MOVLW   AAh                     ;
MOVWF   EECON2                  ;Write AAh
BSF     EECON1, WR              ;Set WR bit to begin write
BSF     INTCON, GIE             ;Enable INTs.
SLEEP                  ;Wait for interrupt to signal write complete
; END REQUIRED SEQUENCE
BCF     EECON1, WREN   ;Disable writes
BANKSEL 0x00           ;Bank 0

I noticed that you are specifically missing this line:

 BCF     EECON1, EEPGD ;Point to DATA memory

If EEPGD is always set, then you'll try to write to program memory (aka overwrite the flash program memory) which should always fail unless you've gone out of your way to specifically enable that.

Aside from that, as far as I can tell from reading your code, everything else looks fine. It's okay that you're polling EECON1.WR instead of setting an interrupt. It will cost you more power than putting the device to sleep, but of course you should just worry about one thing at a time.

这篇关于写入EEPROM的PIC的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆