• Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

PIC 16f876 data eeprom write

Status
Not open for further replies.

SuperBud

New Member
I have a problem with data eeprom write routine. I use the routine in PIC's datasheet but pic doesn't esc of sleep mode.
Can you help me?

Thank you
SuperBud
 

motion

New Member
You might get responses if people could understand what you mean. Could you please explain your question a little bit clearer please.
 

SuperBud

New Member
This is the routine :
;---------------------------------------------
; the value to write is in variable sup
; the address si in register w
;--------------------------------------------
Scrivi_Dato
BSF STATUS, RP1
BCF STATUS, RP0 ; Bank 2
movwf EEADR ; EEADR<=w
Banksel sup
Movf sup,0 ;w<=sup
BSF STATUS, RP1
BCF STATUS, RP0 ; Bank 2
movwf EEDATA ;EEDATA<=w
BSF STATUS,RP0 ; Banco 3
BCF EECON1,EEPGD ;Punta alla Data Memory
BSF EECON1,WREN ;Abilito la scrittura

BCF INTCON,GIE ;Disabilita interrupt
movlw 55h
movwf EECON2
movlw 0AAh
movwf EECON2
BSF EECON1,WR ;Abilito scrittura
BSF INTCON,GIE ;Abilita interrupt

SLEEP
BCF EECON1,WREN ;Disabilito scrittura
Return

the program remains blocked on instruction SLEEP.
Excuse me for my bad English i hope that you can understand my problem and help me.
Thank you
Bye
 

motion

New Member
In addition to the global interrupt enable GIE, I think you need to enable EEIE bit in PIR2 to get an interrupt to come out of SLEEP. You also have to have an interrupt service routine at location 4 to clear the EEIF bit.

I don't use this routine myself. Since writing to the eeprom takes a long time, I simply return from this eeprom write routine and clear the WREN bit elsewhere. Anyway, a simpler routine instead of using SLEEP and interrupts is as follows:

Code:
WAIT:
    BTFSC    EECON1,WR
    GOTO     WAIT
    BCF      EECON1,WREN
 
Status
Not open for further replies.

EE World Online Articles

Loading
Top