|
|
View previous topic :: View next topic |
Author |
Message |
karlo
Joined: 07 Jan 2008 Posts: 10
|
defining constants in the EEPROM memory |
Posted: Mon Jan 07, 2008 8:00 am |
|
|
Hello,
I'm using a 16f628
I'd like to put a few constants in the eeprom memory, a common solution for this is
#rom 0x2100={1,2,3,4,5,6,7,8}
because my ROM memory is almost full i'd like to do it in the beginning of the listing with
#org 2100
write_eeprom()
{
}
Somehow the compiler gives an error with no message and the compiler don't stop
Something is wrong, but in the helpfile i can't find a practical solution for this.
any thanks |
|
|
Ttelmah Guest
|
|
Posted: Mon Jan 07, 2008 8:24 am |
|
|
You are misunderstanding the effect of the directives.
#ROM, puts the following bytes, into a location in the memory 'space' of the chip. On the 16 chips, the 0x2100 location, is 'special', and when the chip is programmed, addresses the EEPROM of the chip (not the normal program ROM). So, the #ROM statement you give, will put the bytes '1,2,3,4,5,6,7', into the EEPROM.
#ORG, puts the _code_ that follows into a specified location. You _cannot_ put code into the EEPROM. Hence the error.
You can put constants into the program memory, simply use the 'const' declaration on a variable. So:
const int8 constvals[] = {1,2,3,4,5,6,7};
generates a seven byte array,that is held in the program memory. Downside is that there is some space overhead involved in doing this.
Best Wishes |
|
|
karlo
Joined: 07 Jan 2008 Posts: 10
|
|
Posted: Wed Jan 09, 2008 6:48 am |
|
|
Thanks,
I tried the #ROM 2100 command and it really don't affect the ROM counter during compiling. |
|
|
Ttelmah Guest
|
|
Posted: Wed Jan 09, 2008 7:19 am |
|
|
Of course it won't. It puts the data in the _EEPROM_, not the program ROM. The ROM counter though will go up, when you use the 'read_eeprom' code, to _access_ this data.
Best Wishes |
|
|
psebast1
Joined: 13 Dec 2006 Posts: 2
|
EEPROM 16f877 query |
Posted: Fri Jan 11, 2008 3:45 am |
|
|
Dear all,
Got a query of if i am doing something wrong. This is a modification on the code available. The first read at location 10 does not get any data (it only displays '00' especially after this location has been defined with data with the #rom statement. However, the second write and read to EEPROM at location 10 yields the correct data and the following read and write to location 10.
Could anyone please advise if I am doing something wrong.
Thanks
#include <16f877.h>
#fuses HS, NOWDT, NOPROTECT, NOBROWNOUT, NOPUT, NOLVP
#use delay(clock = 10000000)
//#use rs232(baud = 9600, xmit=PIN_C6, rcv = PIN_C7, ERRORS)
//===========================================
#include <LCD>
#rom 0x2100 ={1,2,3,4,5,6,7,8,9,10,11,12,13,15}
main()
{
lcd_init();
lcd_gotoxy(1,1);
printf(lcd_putc,"Start");
//printf("Start\n\r\n\r");
delay_ms(4000);
lcd_gotoxy(1,1);
printf(lcd_putc,"Read fr add 10\n\r");
delay_ms(3000);
lcd_gotoxy(1,2);
printf(lcd_putc,"Read %X\n\r", read_eeprom(10));
delay_ms(3000);
write_eeprom(0, 0x55);
lcd_gotoxy(1,1);
printf(lcd_putc,"Wrote 0x55 to eeprom address 0\n\r");
delay_ms(3000);
lcd_gotoxy(1,2);
printf(lcd_putc,"Read %X\n\r", read_eeprom(0));
//printf("\n\r");
delay_ms(3000);
write_eeprom(0, 0xAA);
lcd_gotoxy(1,1);
printf(lcd_putc,"Wrote 0xAA to eeprom address 0\n\r");
lcd_gotoxy(1,2);
printf(lcd_putc,"Read %X\n\r", read_eeprom(0));
delay_ms(3000);
//printf("\n\rDone\n\r");
while(1);
} |
|
|
Ttelmah Guest
|
|
Posted: Fri Jan 11, 2008 4:08 am |
|
|
Check the operation of your programmer.
Put the code into the chip, read it back, and look at the EPROM bytes (there should be a method of dong this somewhere). I have seem some 'kit' programmers that write the bytes to the wrong locations, and some that fail to handle the EEPROM at all...
Best Wishes |
|
|
|
|
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
|