View previous topic :: View next topic |
Author |
Message |
Guestt Guest
|
write / read eeprom -- integers |
Posted: Sat Mar 05, 2005 11:45 am |
|
|
Im using 16F877 and if i write values form 0 to 10 all is working ok.
If i want to write value 240 i get blocked program...
How can i write and read bigger int data to eeprom?
John |
|
|
rwyoung
Joined: 12 Nov 2003 Posts: 563 Location: Lawrence, KS USA
|
|
Posted: Sat Mar 05, 2005 12:01 pm |
|
|
Post smallest possible sample program that exhibits the problem. Also include the compiler version number and programmer type. _________________ Rob Young
The Screw-Up Fairy may just visit you but he has crashed on my couch for the last month! |
|
|
Guestt Guest
|
|
Posted: Sun Mar 06, 2005 4:19 am |
|
|
Code: |
#define adr_bPress 0xF000
....
main()
write_eeprom(adr_bPress,00);
if(bPress())
{
lcd_gotoxy(1,1);
value++;
write_eeprom(adr_bPress,value);
printf(lcd_putc,"%X",value);
} |
Im trying to count from 1 to 240... First 10 numbers are displayed OK but after that nothing happens.
2.)
How can i read stored eeprom values thet are in range from 0xF000
to 0xF00A ? |
|
|
Guesst Guest
|
|
Posted: Sun Mar 06, 2005 4:25 am |
|
|
....
compiler version is 3.150 and programmer is ICD2.. |
|
|
Guest
|
|
Posted: Sun Mar 06, 2005 6:33 am |
|
|
With this code, you will wear out the EEPROM very fast!
Take care and write data only when needed. |
|
|
Guest Guest
|
|
Posted: Sun Mar 06, 2005 7:40 am |
|
|
... any suggestions or example code how to make this on correct way? |
|
|
rwyoung
Joined: 12 Nov 2003 Posts: 563 Location: Lawrence, KS USA
|
|
Posted: Sun Mar 06, 2005 8:48 am |
|
|
Forgetting for a moment that you are going to wear-out the EEPROM quickly with your code, I can't tell much from what you posted. I should have been more explicit and said the SMALLEST POSSIBLE COMPLETE PROGRAM.
Given the age of your compiler I'd suspect it isn't doing the internal eeprom write correctly. Look at the LST file and compare the code associated with "write_eeprom" with the datasheet for your part. There will be a section in the datasheet that discusses the internal EEPROM and the correct way to write. And depending on your exact part, you may also need to check the errata. _________________ Rob Young
The Screw-Up Fairy may just visit you but he has crashed on my couch for the last month! |
|
|
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Sun Mar 06, 2005 9:11 am |
|
|
From what he posted, he is not able to get the printf command to work correctly. He doesn't even read the eeprom values. |
|
|
Guestt Guest
|
|
Posted: Mon Mar 07, 2005 12:26 pm |
|
|
Code: | #include <16F877.h>
#include <lcd.c>
#device adc=8
#use delay(clock=20000000)
#fuses HS,WDT
#define adr_bPress 0x00
void main()
{
lcd_init();
setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_OFF);
setup_psp(PSP_DISABLED);
setup_spi(FALSE);
setup_counters(RTCC_INTERNAL,WDT_18MS);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
write_eeprom(adr_bPress,00);
if(INPUT(PIN_B0))
{
//lcd_gotoxy(1,1);
value++;
write_eeprom(adr_bPress,value);
printf(lcd_putc,"%X",read_eeprom(adr_bPress));
}
} |
/// ---- this is what im using BUT ich need some new(better) way to to this. Can you give me some eg. from 1 to 500 ?
Manfred |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Mon Mar 07, 2005 2:53 pm |
|
|
You are telling us you want to have an improved version of the shown code, but which part exactly do you need improvement on? It looks fine to me, so what is the reason you want suggestions for improvement?
The only problem I can think of is that the eeprom is specified to a minimum of 100.000 write cycles, say 10.000 to be on the safe side. How often is your program going to write to the eeprom? |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Mar 07, 2005 3:19 pm |
|
|
Quote: |
#define adr_bPress 0xF000
write_eeprom(adr_bPress,00);
|
This can't work. The 16F877 only has 256 bytes of internal eeprom.
The address range is 0x00 to 0xFF. You are trying to write to
an eeprom address that does not exist. |
|
|
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Mon Mar 07, 2005 3:29 pm |
|
|
PCM programmer wrote: | Quote: |
#define adr_bPress 0xF000
write_eeprom(adr_bPress,00);
|
This can't work. The 16F877 only has 256 bytes of internal eeprom.
The address range is 0x00 to 0xFF. You are trying to write to
an eeprom address that does not exist. |
Not to mention that he never increments the address if is actually trying to. |
|
|
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
|
Guest Guest
|
|
Posted: Sun Mar 27, 2005 7:12 am |
|
|
Can someone post another "universal" ( for different chips) working example for this task ?
Thank you in advance |
|
|
Guest Guest
|
|
Posted: Sun Mar 27, 2005 7:45 am |
|
|
.... forgot to mention, im counting this and i overwrite last value with the new one. |
|
|
|