PDA

View Full Version : pic12f629 EEPROM problem in MPLABSIM



nicholastyc
- 16th May 2008, 16:20
Hi,
By the way, my new problem is i saved my data (0x01) into eeprom address 0x01, when i recall the data it does not recall the same data but something different from it and sometimes i can save the data and recall correctly but sometimes not.
What is the problem? is the setting or code problems? i already DOUBLExDouble check it in the DATASHEET for few hours and look for solutions on internet, i still cant recall correctly, PLEASe HELP.I write the data correctly...everytime, when i check in the EEDATA register b4 i reset the MPLAB SIM and rerun again.
Code Below, PIC12F629 ,
WRITE code from me,
ORIGINAL_PWM EQU 0x21
TEMP EQU 0x22
WRITE: BSF STATUS,5; switch to bank 1
MOVLW 0x01; go to addr 0x01
MOVWF EEADR;
MOVF ORIGINAL_PWM,w ; (ORIGINAL_PWM = 0x01)
MOVWF EEDATA; write 0x01 to EEDATA
BSF EECON1,WREN; < follow the datasheet write process
BCF INTCON,GIE ;<
MOVLW H'0055' ;<
MOVWF EECON2 ;<
MOVLW H'00AA' ;<
MOVWF EECON2 ;<
BSF EECON1,WR ;<
BSF INTCON,GIE ;<
BCF STATUS,5; switch to bank 0
RETURN

READ: BSF STATUS,5; switch to bank 1
MOVLW 0x01; goto addr 0x01 in eeprom
MOVWF EEADR;
BSF EECON1,RD ; read previously saved data 0x01
MOVF EEDATA,w ; move 0x01 to w
MOVWF TEMP; (TEMP register ) move 0x01 to TEMP
BCF STATUS,5; switch bank 0
RETURN


Thanks for help

mister_e
- 16th May 2008, 18:10
MPSIM can be a real pain in few occasion, what i suggest is to loop on the READ subroutine and wait the Watch Windows to refresh.



include P12F629.inc
errorlevel -302
__CONFIG _INTRC_OSC_NOCLKOUT & _MCLRE_ON & _WDT_OFF & _PWRTE_ON & _BODEN_ON

MyData = 0xFA ; whatever your value
MyAddr = 0x10 ; EEPROM Address
TEMP EQU 0x21

org 0
call WRITE
call READ
goto $-1



WRITE:
BANKSEL EECON1
MOVLW MyAddr
MOVWF EEADR
MOVLW MyData
MOVWF EEDATA
BSF EECON1,WREN
MOVLW 0X55
MOVWF EECON2
MOVLW 0XAA
MOVWF EECON2
BSF EECON1,WR
BCF EECON1,WREN
RETURN

READ:
BANKSEL EEADR
MOVLW MyAddr
MOVWF EEADR;
BSF EECON1,RD
MOVF EEDATA,W
BANKSEL TEMP
MOVWF TEMP
RETURN

end

NOTE: This may not work in 'Animate' mode.