Problem Writing EEPROM into PIC16F887. Please help.Thank you very much

Discussion in 'Embedded Systems and Microcontrollers' started by zhengkoon8, Dec 10, 2011.

  1. zhengkoon8

    Thread Starter New Member

    Nov 28, 2011
    10
    0
    Below is the code of me for writing the number into the PIC. And I am using the datasheet code but is not writing into it. Can anyone tell me why?

    After the program write, I press EEDATA then View EEPROM but the value not change at all. Can someone tell me why?

    Thank you very much for the help


    BANKSEL EEADR ; select Bank EEPROM ADDRESS REGISTER
    MOVLW b'00110000' ; write b'00110000' into work register
    MOVWF EEADR ; Data Memory Address to write
    MOVLW b'00110000' ; write b'00110000' into work register
    MOVWF EEDAT ; Data Memory Value to write
    BANKSEL EECON1 ; select Bank EEPROM CONTROL REGISTER
    BCF EECON1, EEPGD ; Point to DATA memory
    BSF EECON1, WREN ; Enable writes
    BCF INTCON, GIE ; Disable INTs.
    BTFSC INTCON, GIE ; test if the global interrupt is clear, SEE AN576
    GOTO $-2 ; go back two lines
    MOVLW 0x01 ; write b'00000001' into work register
    MOVWF EECON2 ; Write 1 into first byte
    MOVLW 0x02 ; write b'00000010' into work register
    MOVWF EECON2 ; Write 2 into second byte
    BSF EECON1, WR ; Set WR bit to begin write
    BSF INTCON, GIE ; Enable INTs.
    BCF EECON1, WREN ; Disable writes
    BCF STATUS, RP0 ; select Bank 2
    BCF STATUS, RP1 ; select Bank 0
     
  2. thatoneguy

    AAC Fanatic!

    Feb 19, 2009
    6,357
    718
    Ok, a few details left out.

    Which uC
    What are you using for a programming/debugging tool?
    What compiler language and vendor are you using, it appears to be assembly for PIC, but want to be sure.
     
    zhengkoon8 likes this.
  3. Markd77

    Senior Member

    Sep 7, 2009
    2,803
    594
    PIC16F887, it's in the subject line.

    It takes a while to write to EEPROM, the simulator simulates that delay. If you check the WR bit in a loop, then when it gets cleared, the write is complete and the value readable.

    <ed>Looking at it again, you are not using the required sequence of writing 0x55 and 0xaa to EECON2, it's kind of like a password, if your code is different the write will fail</ed>
     
    Last edited: Dec 10, 2011
    zhengkoon8 likes this.
  4. zhengkoon8

    Thread Starter New Member

    Nov 28, 2011
    10
    0
    To thatoneguy:

    the uC that i use is PIC16F887.
    I am using it to program it. which mean i need to write xx number into eeprom
    third, i am using assembly language to program it :)

    Thanks for the reply, hope u can point out what wrong.
     
  5. zhengkoon8

    Thread Starter New Member

    Nov 28, 2011
    10
    0
    to Markd77:

    so how i know when the bit is ready to be readable.
    and if like u say the 0x55 and 0xaa is like that password, then where should i writing the XX number into it? is it after BSF EECON1, WR ; Set WR bit to begin write? the i using movlw xx then movwf to <register>?

    Thanks for the reply. hope to get your reply soon :)
     
  6. Markd77

    Senior Member

    Sep 7, 2009
    2,803
    594
    You seem to have copied the section from the datasheet but then changed part of it. It will work if you change it back, but there is a delay, as I have explained.
     
    zhengkoon8 likes this.
Loading...