Programming 16f872 data eeprom memory

Started by Chris July 6, 2004
Just checking to see if anyone knows of any problem with the
microchip method of programming eeprom data (not program) bytes using
the method described in the 16f872 datasheet. I can't work out where
the problem is, but my code crashes and freezes when I use their
example. Wondered if anyone has any tips for success ?

Chris



> Just checking to see if anyone knows of any problem with the
> microchip method of programming eeprom data (not program) bytes using
> the method described in the 16f872 datasheet. I can't work out where
> the problem is, but my code crashes and freezes when I use their
> example. Wondered if anyone has any tips for success ?

Rule number one: Never, I repeat, never use code examples from Data Sheet.
Use code examples from Application Notes :)) I had serious trouble with code
examples from 16F872 Data Sheet some 5 years ago.

Place data in "ee_data" and address in "ee_adr" and then call EEWrite. Both
"ee_data" and "ee_adr" can be in *any* RAM bank. Just copy this to MPLAB and
use MPSIM to verify its functionality. Then use EEWrite in your code or
change it as you like.

PROCESSOR 16F872
__CONFIG b'00110000001001'
#INCLUDE "p16f872.inc"

RESET_ADR EQU 0x000
RAM_START EQU 0x020

CBLOCK RAM_START
ee_data
ee_adr
ENDC

ORG RESET_ADR

movlw 1
movwf ee_data
clrf ee_adr
call EEWrite
incf ee_adr, F
call EEWrite
Loop goto Loop

EEWrite
banksel ee_data
movf ee_data, W
banksel EEDATA
movwf EEDATA
banksel ee_adr
movf ee_adr, W
banksel EEADR
movwf EEADR
banksel INTCON
l1_eewrite bcf INTCON, GIE
btfsc INTCON, GIE
goto l1_eewrite
banksel EECON1
bcf EECON1, EEPGD
bcf EECON1, WRERR
bsf EECON1, WREN
movlw 55h
movwf EECON2
movlw 0AAh
movwf EECON2
bsf EECON1, WR
nop
nop
nop
nop
banksel PIR2
l2_eewrite btfss PIR2, EEIF
goto l2_eewrite
bcf PIR2, EEIF
nop
nop
banksel EECON1
bcf EECON1, WREN
bsf INTCON, GIE
bcf STATUS, RP0
bcf STATUS, RP1
return

END

Please note that after "return" from "EEWrite" you are in RAM bank 0!

Do not place "banksel" directive in the same line with "EEWrite" label or
MPASM will report error. That's why "banksel" directive is bellow "EEWrite"
label!!!

EEWrite is taken directly from one of my applications so it is going to work
for sure.

Regards,
Igor



I've used the 16F872 quite a bit, including writing and reading from EEPROM.
I've not had any freezing problems with it, but I did have those symptoms
with some 16F627A chips earlier this year. For this, I later found an errata
sheet that documented the problem, with a workaround. (I ended up changing
to 16F627 chips instead).

Perhaps a newer batch of 16F872 chips has this problem? Check the errata
sheets to see if you find anything.

Cheers,
-Neil.
On Tuesday 06 July 2004 11:01 am, Chris scribbled:
> Just checking to see if anyone knows of any problem with the
> microchip method of programming eeprom data (not program) bytes using
> the method described in the 16f872 datasheet. I can't work out where
> the problem is, but my code crashes and freezes when I use their
> example. Wondered if anyone has any tips for success ?
>
> Chris >
>
> to unsubscribe, go to http://www.yahoogroups.com and follow the
> instructions Yahoo! Groups Links >