Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

This code does not work, does not record in the EEPROM.

Status
Not open for further replies.

REHome

Newbie level 6
Joined
Feb 23, 2008
Messages
12
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,372
Hello:

**broken link removed**

PIC is jammed me both physically and Proteus simulator, does not record in its internal EEPROM PIC16F88.

What the main program PIC with a button on RA0 on and off an LED on RB0 output.

So far so good. Just not able to record anything in the EEPROM when the LED is on or off, the EEPROM function does is that, keep what values ​​Led past.

I always stuck around.
, Save in the EEPROM output value.
;Guarda en la EEPROM el valor de la salida.
Escribe_Dato_EERPOM
BANKSEL EEADR
movlw 0x00 ; Dirección.
movwf EEADR ; Carga registro EEADR con la dirección a escribir.
movf Dato,W
movwf EEDATA ; Carga el registro EEDATA con el dato a escribir.
BANKSEL EECON1
bcf EECON1,EEPGD ; Selecciona acceso a memoria EEPROM de datos.
bsf EECON1,WREN ; Permiso de escritura.
movlw 0x55
movwf EECON2
movlw 0xAA
movwf EECON2 ; Secuencia de escritura según Mirochip.
bsf EECON1,WR ; Inicio del ciclo de escritura.
Espera
btfsc EECON1,WR[/style]
goto Espera ; Esperar que finalice (WR=0).

bcf EECON1,WREN ; Retira el permiso de escritura.
return

Code:
; Cada vez que presiona el pulsador conectado a la línea RA0 conmutará el estado de
; un LED conectado a la línea RB0.
;
; ZONA DE DATOS **********************************************************************

    LIST        P=16F88
    INCLUDE     <P16F88.INC>
    __CONFIG    _CONFIG1, _CP_OFF & _CCP1_RB0 & _DEBUG_OFF & _WRT_PROTECT_OFF & _CPD_OFF & _LVP_OFF & _BODEN_OFF & _MCLR_ON & _PWRTE_ON & _WDT_OFF & _FOSC_EC
    __CONFIG    _CONFIG2, _IESO_OFF & _FCMEN_OFF
    ERRORLEVEL    -302
   
    CBLOCK 0x20
    RAM_ret
    RAM_ret_1
    ENDC

    CBLOCK 0x110
    Dato
    ENDC

#DEFINE Pulsador   PORTA,0        ; Pulsador conectado a RA0.
#DEFINE Led        PORTB,0        ; Línea donde se conecta el diodo LED.


; ZONA DE CÓDIGOS ********************************************************************

    ORG     0
Inicio
    clrw
    clrf    PORTB               ; Borra los latch de salida.
    BANKSEL ANSEL
    clrf    ANSEL               ; Puerto A digital.
    BANKSEL TRISA
    movlw    b'11111111'
    bsf     Pulsador           ; Pulsador activado como entrada.
    clrf    TRISB
    bcf     Led                ; Activar como salida Led.
    call    Lee_Dato_EERPOM_2
    BANKSEL PORTA               ; Vuelve al banco 0.
Principal
    btfsc   Pulsador            ; ¿Pulsador presionado?, ¿(Pulsador)=0?
    goto    Fin                    ; No. Vuelve a leerlo.
;    call    Retardo_20ms        ; Espera que se estabilicen los niveles de tensión.
    btfsc   Pulsador            ; Comprueba si es un rebote.
    goto    Fin                    ; Era un rebote y sale fuera.
    btfsc   Led                ; Testea el último estado del LED.
    goto    EstabaEncendido
EstabaApagado
    bsf     Led                ; Estaba apagado y lo enciende.
    ;movlw    b'00000001'
    BANKSEL    Dato
    movf    Led
    movwf    Dato
    call    Escribe_Dato_EERPOM_2
    BANKSEL    PORTA                ; Banco 0.
    goto    EsperaDejePulsar
EstabaEncendido
    bcf     Led                ; Estaba encendido y lo apaga.
    ;movlw    b'00000000'
    movf    Led
    movwf    Dato
    call    Escribe_Dato_EERPOM_2
    BANKSEL    PORTA                ; Banco 0.
EsperaDejePulsar
    btfss   Pulsador            ; ¿Dejó de pulsar?. ¿(Pulsador)=1?
    goto    EsperaDejePulsar    ; No. Espera que deje de pulsar.
Fin
    goto    Principal

;Subrutina EEPROM ******************************************************************
Lee_Dato_EEPROM
    BANKSEL EEADR
    movlw   0x00                    ; Dirección.
    movwf   EEADR                   ; Carga el registro EEADR con la dirección que se desea leer.
    BANKSEL EECON1
    bcf     EECON1,EEPGD            ; Selecciona el acceso a memoria EEPROM.
    bsf        EECON1,RD               ; Inicia el ciclo de lectura.
    BANKSEL EEDATA
    movf    EEDATA,W                ; Carga en W el dato recuén leído.
    return

;Guarda en la EEPROM el valor de la salida.
Escribe_Dato_EERPOM
    BANKSEL EEADR
    movlw   0x00                    ; Dirección.
    movwf   EEADR                   ; Carga registro EEADR con la dirección a escribir.
    movf    Dato,W
    movwf   EEDATA                  ; Carga el registro EEDATA con el dato a escribir.
    BANKSEL EECON1
    bcf     EECON1,EEPGD            ; Selecciona acceso a memoria EEPROM de datos.
    bsf     EECON1,WREN             ; Permiso de escritura.
    movlw   0x55
    movwf   EECON2
    movlw   0xAA
    movwf   EECON2                  ; Secuencia de escritura según Mirochip.
    bsf     EECON1,WR               ; Inicio del ciclo de escritura.
Espera
    btfsc   EECON1,WR
    goto    Espera                  ; Esperar que finalice (WR=0).
    bcf     EECON1,WREN             ; Retira el permiso de escritura.
    return

     END

Any idea?

Greeting.
 

Yes.

Use the PIC's internal EEPROM.
 

Hi,

Have always used this routine for eeprom write, which checks the Interrupt flag rather than WR.

Its from a 876/7A chip but the registers appear in the same banks as the 88.

Code:
eewrite	bsf	STATUS,RP0		; select bank1
	movfw	CHOURS			; get Chours
	bcf		STATUS,RP0		; reset to bank0
	bsf		STATUS,RP1		; select bank2
	movwf	EEDATA			; load Chours to EEdata
	movlw	0x00			; load eeaddresss 00
	movwf	EEADR			;
	bcf		STATUS,RP1		; reset to bank0

	bsf		STATUS,RP0		; select bank1 EEWRITE
	bsf		STATUS,RP1		; select bank3
	bcf		EECON1,EEPGD	; points to data memory
	bsf		EECON1,WREN		; enable write
	bcf		INTCON,GIE		; disable all ints
	movlw	0x55			;
    movwf	EECON2			; init write sequence
	movlw	0xAA			; using 2 instructions	
	movwf	EECON2			;
	bsf		EECON1,WR		; write data
	bsf		INTCON,GIE		; turn ints back on
	bcf		STATUS,RP0		; select bank0
	bcf		STATUS,RP1		;
wd01 btfss	PIR2,EEIF		; is int bit on ie WRTDONE
	goto	wd01			; if done continue
	bcf		PIR2,EEIF		; reset interupt
 	bsf		STATUS,RP0		; select bank3
	bsf		STATUS,RP1
	bcf		EECON1,WREN		; disables write
	bcf		STATUS,RP1		; select bank1
	bcf		STATUS,RP0		; select bank0
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top