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

Thread Starter

zhengkoon8

Joined Nov 28, 2011
10
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
 

thatoneguy

Joined Feb 19, 2009
6,359
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.
 

Markd77

Joined Sep 7, 2009
2,806
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:

Thread Starter

zhengkoon8

Joined Nov 28, 2011
10
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.
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.
 

Thread Starter

zhengkoon8

Joined Nov 28, 2011
10
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>
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 :)
 

Markd77

Joined Sep 7, 2009
2,806
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.
 
Top