PIC18F4620 Internal EEPROM

Status
Not open for further replies.

Pyromanci

New Member
Hello,

I have been reading up reading and writing to the internal EEPROM of a PIC. After reading and doing some research i still have some questions.

One question i have is if i were to take a dynamic string say Dstring. Get it a default value of say "default". Is there a way to write that right to the eeprom at the address i specify? my attempts at it all seem to fail, but when i write just basic bit codes it works just fine.

here is a little sample of what i am talking about.
main ()
{
string *Dstring = "default";
int i;
short addr = 0x000;
for(i=0; i<strlen(Dstring); i++)
{
EEpromPut(addr++,Dstring);
}
}


void EEpromPut(short addr, char data)
{
WORDbytes temp;
temp.data=addr;
EEADRH = temp.high;
EEADR = temp.low;
EEDATA = data;
EECON1bits.EEPGD = 0;
EECON1bits.CFGS = 0;
EECON1bits.WREN = 1;
INTCONbits.GIE=0;
_asm
MOVLW 0x55
MOVWF EECON2,0
MOVLW 0xAA
MOVWF EECON2,0
_endasm
EECON1bits.WR=1;
while (EECON1bits.WR == 1){};
INTCONbits.GIE=1;
EECON1bits.WREN = 0;
}

when that runs i end up with all bit values of 0x15 or 0x14 for address range of 0x000-0x006. The write range is correct, but the data written is incorrect. Do i have to run convert each character of Dstring to its hex value before i write?

Thanks for the help in advance.
 
You've declared a pointer to a "string" type, then initialized the pointer with a value. This isn't going to do what you think it does. It will actually assign a value to the pointer rather than to the memory location given by the pointer.

Try

char dstring[8];
strcpy (dstring, "default");
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…