programing eeprom of a pic16f684

Thread Starter

DHEN

Joined Dec 7, 2009
9
Working on a project with the PIC16F684 MU, where i need to store a value (30H) in the EEPROM. i followed the instructions in the manual for writing to the eeprom.

Link To Manual: http://ww1.microchip.com/downloads/en/DeviceDoc/41202F-print.pdf

This is my code:
------------------------------------------------
BSF 03H,5 ; BANK 1

MOVLW B'1'
MOVWF 9BH;EEADR
BCF 03H,5 ; BANK 0
MOVLW 30H ; data i want stored in address 1 of the eeprom
BSF 03H,5 ; BANK 1
MOVWF 9AH;EEDAT

BSF 03H,5 ; BANK 1
BSF 9CH,2;WREN
BCF 8BH,7;GIE
BTFSC 8BH,7
GOTO $-2
MOVLW B'01010101'
MOVWF 9DH ;EECON2
MOVLW B'10101010'
MOVWF 9DH ; EECON2
BSF 9CH,1;WR
BSF 8BH,7
BCF 03H,5 ; BANK 0
RETURN
------------------------------------------
when i run this code in MPLAB and ISIS the eeprom stays at FF regardless of the value in register 30H :confused:.

Any help would be greatly appreciated!!!!
 

t06afre

Joined May 11, 2009
5,934
I do not work with your chip, but I have worked with the 16f690. Your write sequence to ECON2 must be checked I think it is 0x55, then 0xAA, and so set the WR bit in ECON1
 

eblc1388

Joined Nov 28, 2008
1,542
when i run this code in MPLAB and ISIS the eeprom stays at FF regardless of the value in register 30H :confused:.
EEPROM write takes many clock cycles to complete, and the program uses interrupts to wait for the write to finish. Because the PIC simulator model also implements this delayed writing timing behavior, the simulation might seem to run very slowly - please be patient. Don't expect an immediate change of value in the EEPROM.

Just place a breakpoint after the whole EEPROM writing routine. Then go and have a cup of coffee, relax.
 

t06afre

Joined May 11, 2009
5,934
Sorry I forget to mention this in my last mail. Then using the MPLAB SIM tool, do not run at max speed. In the MPLAB toolbar select Debugger->setting and the select the OSC/TRace tab. Set your CPU speed to 4MHz. This work on my computer, and I hope it will work on your.
Here is a correct code. You code was somewhat messy. Please post code with better comments next time. Even if you are frustrated and struggle big time like now.
Ps in my code I did not include any interrupt configuration. But the data sheet recommend turning off interrupt before starting the EEPROM write cycle
Rich (BB code):
BANKSEL EEADR ;Select Memory Bank 2
MOVLW 1;
MOVWF EEADR ;Data Memory Address to write
MOVLW 0x30
MOVWF EEDAT ;Data Memory Value to write
BANKSEL EECON1 ;Select Memory Bank 3
BCF EECON1, EEPGD ;Point to DATA memory
BSF EECON1, WREN ;Enable writes
MOVLW 0x55 ;
MOVWF EECON2 ;Write 55h
MOVLW 0xAA ;
MOVWF EECON2 ;Write AAh
BSF EECON1, WR ;Set WR bit to begin write
BANKSEL 0x00 ;Select Memory Bank 0
 

Thread Starter

DHEN

Joined Dec 7, 2009
9
Sorry about the messy code. I do appreciate your help!

on line 7 of your code:
BCF EECON1, EEPGD ;Point to DATA memory

i don't understand what EEPGD Means. the manual shows the EECON1 regisiter as:
|address| Name | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
| 9Ch | EECON1| —| —| —| —| WRERR| WREN| WR| RD|
 
Top