View previous topic :: View next topic |
Author |
Message |
joven
Joined: 30 Jan 2007 Posts: 56 Location: Viana do Castelo - Portugal
|
EEPROM |
Posted: Tue Mar 24, 2009 8:44 am |
|
|
Hi
How can put eeprom data in the program code.
the hex file have after compiling?
Thanks |
|
|
Ttelmah Guest
|
|
Posted: Tue Mar 24, 2009 9:17 am |
|
|
How about using the search engine?
You can't add a hex file after compiling, except to load it separately into your programmer. You can include any data you want into the EEPROM, with the #ROM statement. A search here will tell you how to do it.
Best Wishes |
|
|
AsmallGuy Guest
|
|
Posted: Wed Apr 01, 2009 6:22 am |
|
|
I can give you some hints:
_first, try to find the address of the EEPROM locations for your specific PIC, example a PIC16F684 has it starting from 0x2100 up to 0x21FF (guess, 256 storage bytes)
_second:
Code: |
#define my_storage 0x2100 // starting address
#rom my_storage={0x0F} // actual row to embed EEPROM in .hex file
|
Here you assign the value 0x0F to the location; you can add elements with commas; remember, you can ONLY STORE BYTEs, like 8-bits, no native approach to complex data type..
_third:
Code: |
variable=read_EEPROM (my_storage);
|
Here it is, enough to start |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Apr 01, 2009 11:22 am |
|
|
Quote: | #define my_storage 0x2100
variable=read_EEPROM (my_storage); |
This is not correct. The read_eeprom() function does not take the
hardware programming address of the eeprom as a parameter.
For a PIC that has 256 bytes of eeprom, the address used with
read_eeprom() should be in the range 0x00 to 0xFF.
This is stated in the manual:
Quote: | read_eeprom()
Syntax: value = read_eeprom (address)
Parameters: address is an (8 bit or 16 bit depending on the part) int
Returns: An 8 bit int
Function: Reads a byte from the specified data EEPROM address.
The address begins at 0 and the range depends on the part. |
http://www.ccsinfo.com/downloads/ccs_c_manual.pdf |
|
|
AsmallGuy Guest
|
|
Posted: Thu Apr 02, 2009 4:18 am |
|
|
Really?.. i wrote this test program using for my 16F684 (i've used also flex_lcd.c to see directly from the PIC):
Code: |
#define low 0x2100
#define hig 0x2101
//#rom low={0x0F} disabled, no forced initialization
//#rom hig={0x0F}
int8 lowv=0;
int8 higv=0;
int16 pwm1=400;
...cut...
lowv=pwm1;
higv=(pwm1>>8);
write_eeprom(low,lowv);
write_eeprom(hig,higv);
lowv=higv=0;
lowv=read_EEPROM (low);
higv=read_EEPROM (hig);
pwm1=make16(higv,lowv);
printf(lcd_putc,"\fN1: %u N2: %u\nPwm: %Lu",higv,lowv,pwm1);
...
|
I'm seeing values: "1" and "144" and "400" which are correctly saved and retrieved from the EEPROM.
Could all this work only by chance of lucky numbers/addresses? i'm going to debug more and try so! can you replicate that in your environment? |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Apr 02, 2009 10:22 am |
|
|
Quote: | Could all this work only by chance of lucky numbers/addresses ? |
That is correct. You are giving a 16-bit address to the read_eeprom()
function. It only uses the lower 8-bits. It throws away any upper bytes
that you give it. So it's working in spite of your error. |
|
|
AsmallGuy Guest
|
|
Posted: Fri Apr 03, 2009 2:02 am |
|
|
PCM programmer wrote: |
That is correct. You are giving a 16-bit address to the read_eeprom()
function. It only uses the lower 8-bits. It throws away any upper bytes
that you give it. So it's working in spite of your error. |
Ta-da! there we are :D - i'm getting used to this kind of approach! |
|
|
|