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 CCS Technical Support

EEPROM & 18f452

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



Joined: 19 May 2012
Posts: 26
Location: Pakistan

View user's profile Send private message

EEPROM & 18f452
PostPosted: Mon May 28, 2012 2:23 am     Reply with quote

Compiler v 4.120
Controller: 18f452

Code:

#Define EEPROM_add   10

write_eeprom(EEPROM_add,lockout);
lockout = read_eeprom(EEPROM_add);



Although the program compiles completely but it gives error on a separate window.
"List index out of bounds (49)"

All the function except EEPROM writing & Reading run as usual.
Ttelmah



Joined: 11 Mar 2010
Posts: 19515

View user's profile Send private message

PostPosted: Mon May 28, 2012 2:55 am     Reply with quote

What is 'lockout'?.
Remember also you can often get errors caused by something a few lines before, so simplify, do a little test program, and see if the problem disappears, then look for what is different. If the problem still shows with the test program, you can then post this.

Best Wishes
waheed



Joined: 19 May 2012
Posts: 26
Location: Pakistan

View user's profile Send private message

PostPosted: Mon May 28, 2012 3:43 am     Reply with quote

Test Program works fine except that if switch off my controller than the lockout value is lost i.e. EEPROM isn't working.

it also gives an error in a separate Dialogue Box :
"List Index out of bounds (49)"

Code:

#include <18F452_new.h>
#fuses NOWDT,HS,NOPROTECT
#use delay(clock=20000000)
#include <stdlib.h>
#include <dt_lcd_v01.c>


#define EEPROM_addr   10

int16 lockout=0;
void main()
{
set_tris_a(0);
dt_lcd_init();
dt_lcd_clear_screen();
while (1)
{
if (input(PIN_D0)== 0)
{
lockout++;
}
write_eeprom(EEPROM_addr,lockout);
lockout=read_eeprom(EEPROM_addr);


dt_lcd_gotoxy(0,0);printf(dt_lcd_printchar,"Lockout:   %Lu",lockout);

}
}
Ttelmah



Joined: 11 Mar 2010
Posts: 19515

View user's profile Send private message

PostPosted: Mon May 28, 2012 4:50 am     Reply with quote

What size of data does write_eeprom write/read?. How big is lockout?. Not the same.....

Best Wishes
waheed



Joined: 19 May 2012
Posts: 26
Location: Pakistan

View user's profile Send private message

PostPosted: Mon May 28, 2012 5:18 am     Reply with quote

8 bit data can be written or read.

I have changed the int_count type to int8, but still it doesn't work and gives the same error.
waheed



Joined: 19 May 2012
Posts: 26
Location: Pakistan

View user's profile Send private message

PostPosted: Mon May 28, 2012 7:26 am     Reply with quote

I have changed my code to this:

Code:

#include <18F452_new.h>
#fuses NOWDT,HS,NOPROTECT
#use delay(clock=20000000)
#ROM int8 0xF00000 = {1, 2, 3, 4, 5}
#include <stdlib.h>
#include <dt_lcd_v01.c>

int8 lockout=0;

void main()
{
set_tris_a(0);
dt_lcd_init();
dt_lcd_clear_screen();

while (1)
  {
   if (input(PIN_D0)== 0)
     {
      lockout++;
     }
   write_eeprom(1,lockout);
   dt_lcd_gotoxy(0,0);
   printf(dt_lcd_printchar,"Lockout:  %d", read_eeprom(1));
  }
}

Printf commands reads directly from the EEPROM Location and it shows the correct value. But if I reset the controller, the value is lost.
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Tue May 29, 2012 12:57 am     Reply with quote

An EEPROM cell will not last forever; on every erase cycle it will get damaged a little bit more.
Check out the data sheet for your PIC, a byte will last a minimum of 10k, typical 100k, erase cycles.

You are writing & erasing at full speed. 1 erase/write cycle takes 4ms. How long does it take before you have damaged your chip?..... 40 to 400 seconds. Oops....

Try using another address (and some logic to do less writes per second). If the program then work correctly you know you have crashed the EEPROM cell.
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