EEPROM doesn't return right value after shutoff.

Status
Not open for further replies.
The EECON1,WR bit doesn't clear in sim.

And it doesn't set in debug or release mode, when I reach "bsf EECON1,WR" in the write sequence...???
 
Last edited:
123

these are mine read/writes
Code:
get_epp_val
    movlw 2h
    movwf EEADR
    bsf status, 5         ; bank1
    bsf EECON1, 0       ; read
    bcf status, 5         ; bank0
    movf EEDATA, w    ; w = val from adr 2h
    retlw 0

write_epp_val

    movlw 2h           
    movwf EEADR     ; EEADR = 2h
    movlw 77h
    movwf EEDATA   ; EEDATA = 77h

    bsf status, 5   ; bank1
    bcf intcon, 7   ; int off
    bsf EECON1, 2    ; enable write
    movlw 55h
    movwf EECON2    
    movlw 0AAh
    movwf EECON2   
    bsf EECON1, 1    ; write NOW  77h @adr 2h
    bsf INTCON, 7    ; int on
    bcf status, 5      ; bank0

    retlw 0

    call get_epp_val
or 
    call write_epp_val

always works.....i've also noticed it helps to put some delay after write
not 1 or 2 instructions but something like 10microseconds, but that could be cause i'm still using old pics
 
I'm still not getting a value in EEPROM to write, the WR bit doesn't clear in Sim. I had to include a banksel command to get the value to go from NEW to EEDATA, otherwise it doesn't go to the register.

Could it be because of the banksel commands, that I should use BSF status commands instead?

Here's what I did with it:

Code:
	LIST	p=16F88
	include "P16F88.inc"
	  
__config _CONFIG1, _WDT_OFF & _INTRC_IO & _MCLR_ON & _LVP_OFF 

 errorlevel	-302


	Cblock	0x20
	 OLD,NEW
	endc
	

	
	

	banksel	TRISA		;bank 1
	movlw	0x42		;1MHz clock
	movwf	OSCCON

	

 	goto	start
read

    banksel        EEADR
    movlw           2h
    movwf          EEADR
    bsf               STATUS, 5         ; bank1
    bsf               EECON1, 0       ; read
    bcf               STATUS, 5         ; bank0
    movf            EEDATA, w    ; w = val from adr 2h
    return

write

    movlw           2h           
    movwf           EEADR     ; EEADR = 2h
    movfw            NEW
    banksel          EEDATA
    movwf            EEDATA   
    banksel          EECON1
    bsf                 STATUS, 5   ; bank1
    bcf                 INTCON, 7   ; int off
    bsf                 EECON1, 2    ; enable write
    movlw            55h
    movwf            EECON2    
    movlw            0AAh
    movwf            EECON2   
    bsf                 EECON1, 1    ; write NOW  77h @adr 2h
    bsf                 INTCON, 7    ; int on
    bcf                 STATUS, 5      ; bank0

    return

    
	

start

	call	read
	banksel	OLD
	movwf	OLD
	incf	OLD,f
	movfw	OLD
	movwf	NEW

	call	write

	call read

 	goto start

	end
 
I just tried it all over the place, it still doesn't work in sim or in debug.
Now this is a stubborn bug. Has to be the last one. Everything else works.

I'll try slowing down the clock.

I think I found what the problem is...
write protect must be set in the config files, I have to find where the data is for config files...

getting there...
 
Last edited:
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…