Maker Pro
Maker Pro

How to read and write the EEPROM of a PIC 18F442?

A

Alexander

Jan 1, 1970
0
I want to read and write the EEPROM of my PIC.
Unfortunatly, this doesn't work the way it's intended.
I want to call these functions to be called from an ISR and/or during normal
code execution.
I've added some code to restore the previous GIE state for this.
Could someone help me???

ThanX,

Alexander


WriteEE
MOVLW DATA_EE_ADDR ;
MOVWF EEADR ; Data Memory Address to read
MOVLW DATA_EE_DATA ;
MOVWF EEDATA ; Data Memory Value to write
BCF EECON1, EEPGD ; Point to DATA memory
BCF EECON1, CFGS ; Access program FLASH or Data EEPROM memory

BCF GIETEST ; Save current GIE state
BTFSC INTCON,GIE
BSF INTTEST,GIET
BCF INTCON, GIE ; Disable INTs.
BSF EECON1, WREN ; Enable Write
MOVLW 0x55 ;
MOVWF EECON2 ; 55h must be written to EECON2
MOVLW AAh ; to start write sequence
MOVWF EECON2 ; Write AAh
BSF EECON1,WR ; Set WR bit begin write
BTFSC GIETEST ; Restore GIE state
BSF INTCON,GIE ;

ReadEE ; Adress already in W returns
data in EEDATA
MOVWF EEADR ; Data Memory Address to read
BCF EECON1, EEPGD ; Point to DATA memory
BCF EECON1, CFGS ; Access program FLASH or Data EEPROM memory
BSF EECON1, RD ; EEPROM Read
 
N

NewsGroup

Jan 1, 1970
0
Alexander said:
I want to read and write the EEPROM of my PIC.
Unfortunatly, this doesn't work the way it's intended.
I want to call these functions to be called from an ISR and/or during normal
code execution.
I've added some code to restore the previous GIE state for this.
Could someone help me???
BCF GIETEST ; Save current GIE state
BTFSC INTCON,GIE
BSF INTTEST,GIET
BCF INTCON, GIE ; Disable INTs.

I assume that somewhere you have the line

#define GIETEST INTTEST,GIET

Other than that it looks fine. - I assume that there is no banking with the
18 series as your code has no BSF STATUS,RP0 type instructions.

Mike.
 
A

Alexander

Jan 1, 1970
0
Het volgende bericht werd op ons ingehakt door NewsGroup
I assume that somewhere you have the line

#define GIETEST INTTEST,GIET
Yes, I do have that line included or something like that
Other than that it looks fine. - I assume that there is no banking
with the 18 series as your code has no BSF STATUS,RP0 type
instructions.
I assume the same especially since MPLAB gives me no warning (normally it
does) about this.

ThanX I will take a look at it later with a clear head and add some debug
settings in the code to check everything out.
 
A

Alexander

Jan 1, 1970
0
Found the (at least one) problem.
How stupid can one be ;)
I called the code and forgot the return :(


Het volgende bericht werd op ons ingehakt door Alexander
 
A

Alexander

Jan 1, 1970
0
The code was not completly correct :(
It seemed that only 50% of the writes worked.

So I added a check/wait to see if the previous write sequence was finished
(a W bit somewhere in the intcom register).
After that it worked fine but the following question(s) hit me (not very
hard though):

How long does it take for a write to complete???
Is this (external) oscillator dependend???
Does each write take about the same time???

ThanX,

Alexander


Het volgende bericht werd op ons ingehakt door Alexander
 
Top