CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

PIC18F1320 Internal EEPROM Problem?

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
ritchie



Joined: 13 Sep 2003
Posts: 87

View user's profile Send private message

PIC18F1320 Internal EEPROM Problem?
PostPosted: Tue Mar 16, 2004 6:04 pm     Reply with quote

Hello,

I have a problem with the internal eeprom of pic18f1320?

To view the complete picture... this what happend:
[1] I download the code to the PIC
[2] I execute the run button
[3] check the content to the eeprom then check if its ok

Next...
[4] I turn-off the power
[5] I read the content of the eeprom
[6] Unfortunately it read 0000 instead of 0009

Next....
[7] I plug the ICD cable and the other end to the PIC
[8] I execute the run button
[9] read the content of the eeprom and it read 0009 ---> this is weird?

Anyone have the same problem? can you share some insights.. I really need the internal eeprom if I can't make a workaround I might use a 64bytes external eeprom (microwire I guess).

My eeprom read and write routine below:
Code:

#int_eeprom
void eeprom_isr() // write device address to data eeprom interrupt routine
{
   while (!EEIF); // wait for eeprom write to complete
   EEIF=0;        // clear eeprom interrupt flag
   WREN=0;        // inhibits erase or write cycles?
}


void mtask_write_eeprom(unsigned int8 uiAddr, unsigned int8 uiData)
{
   EEIF = 0;         // make sure that interrupt flag is cleared
   EEDR = uiAddr;    // load address here
   EEDATA = uiData;  // load data here
   EEPGD = 0;        // point to data eeprom memory
   WREN = 1;         // allow erase or write cycles?
   disable_interrupts(global); // required to disable interrupts
   EECON2 = 0x55;    // write 0x55 (a required sequence?)
   EECON2 = 0xAA;    // write 0xAA (a required sequence?)
   EEWR = 1;         // initiates a data eeprom erase/write cycle
   #asm nop #endasm  // one clock cycle delay
   enable_interrupts(global); // restore all interrupts
   while (EEWR);     // wait for write cycle to complete
   #asm nop #endasm  // one clock cycle delay
   return; // return to main
}

unsigned int8 mtask_read_eeprom(unsigned int8 uiAddr)
{
   EEDR = uiAddr;    // load address here
   EEPGD = 0;        // point to data eeprom memory
   #asm nop #endasm  // one clock cycle delay
   EERD = 1;         // initiates a eeprom memory read
   return(EEDATA);   // return EEDATA
}

write_long_int_eeprom(unsigned int8 uiAddr, unsigned int16 ui16Data)
{
   unsigned int8 i;

   for (i=0; i<2; i++)  // write device address into two bytes location
      mtask_write_eeprom(i+uiAddr, *(&ui16Data+i));
}

unsigned int16 read_long_int_eeprom(unsigned int8 uiAddr)
{
   unsigned int8 i;
   unsigned int16 ui16Result;

   for (i=0; i<2; i++)  // read device address from two bytes location
      *(&ui16Result+i) = mtask_read_eeprom(i+uiAddr);
   return(ui16Result);
}



I need your comments and suggestion on this guys and [spam]...

Thank u.
Neutone



Joined: 08 Sep 2003
Posts: 839
Location: Houston

View user's profile Send private message

PostPosted: Tue Mar 16, 2004 11:27 pm     Reply with quote

I would push some values into the EEPROM during programming. At the very least it would double what you know is working.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group