View previous topic :: View next topic |
Author |
Message |
waheed
Joined: 19 May 2012 Posts: 26 Location: Pakistan
|
EEPROM & 18f452 |
Posted: Mon May 28, 2012 2:23 am |
|
|
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
|
|
Posted: Mon May 28, 2012 2:55 am |
|
|
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
|
|
Posted: Mon May 28, 2012 3:43 am |
|
|
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
|
|
Posted: Mon May 28, 2012 4:50 am |
|
|
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
|
|
Posted: Mon May 28, 2012 5:18 am |
|
|
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
|
|
Posted: Mon May 28, 2012 7:26 am |
|
|
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
|
|
Posted: Tue May 29, 2012 12:57 am |
|
|
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. |
|
|
|