|
|
View previous topic :: View next topic |
Author |
Message |
('-') Guest
|
write/read EEPROM need for help!! Thank you |
Posted: Tue Jun 29, 2004 11:25 am |
|
|
I want to read/write data to eeprom. So i read example file from ccs 'intee.c' . but my pic is 18f458. The code is below
Code: | #include <18f458.h>
#fuses HS,NOWDT,NOPROTECT
#use delay(clock=10000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
#include <input.c>
main() {
byte i,j,address,value;
do {
printf("\r\n\nEEPROM:\r\n");
for(i=0; i<=3; ++i) {
for(j=0; j<=15; ++j) {
printf( "%2x ", read_eeprom( i*16+j ) );
}
printf("\n\r");
}
printf("\r\nLocation to change: ");
address = gethex();
printf("\r\nNew value: ");
value = gethex();
write_eeprom( address, value );
} while (TRUE);
} |
The reult is
EEPROM:
01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01
01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01
01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01
01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01
Location to change: 02
New value: 65
EEPROM:
65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65
65 65 65 65 65 65 65 65 65 65 65 65 65 65 65
65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65
65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65
I don't understand why all addresses are changed. And when power off all data is 00. How can i do?. Please give some suggestions to me. Thank you. |
|
|
Guest Guest
|
Is ++i the same as i++ ?? |
Posted: Tue Jun 29, 2004 7:06 pm |
|
|
I don't know "C" very well and am stuck here overseas w/o a book, but is ++i the same as i++ in your "for" statements? |
|
|
dyeatman
Joined: 06 Sep 2003 Posts: 1934 Location: Norman, OK
|
C User Info |
Posted: Tue Jun 29, 2004 8:05 pm |
|
|
Not quite.....
++i means it is incremented before it is used and i++ means it is incremented after it is used.
Here is a good online C User guide:
http://www.newtonlabs.com/ic/ic_toc.html |
|
|
Haplo
Joined: 06 Sep 2003 Posts: 659 Location: Sydney, Australia
|
|
Posted: Tue Jun 29, 2004 10:44 pm |
|
|
When you debug the code, are the variables 'address' and 'value' are actually 65 and 2? In your code I can't see any 'printf' statements to print these out, so I assume in your post you typed them manually. |
|
|
Ttelmah Guest
|
Re: write/read EEPROM need for help!! Thank you |
Posted: Wed Jun 30, 2004 3:47 am |
|
|
('-') wrote: | I want to read/write data to eeprom. So i read example file from ccs 'intee.c' . but my pic is 18f458. The code is below
Code: | #include <18f458.h>
#fuses HS,NOWDT,NOPROTECT
#use delay(clock=10000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
#include <input.c>
main() {
byte i,j,address,value;
do {
printf("\r\n\nEEPROM:\r\n");
for(i=0; i<=3; ++i) {
for(j=0; j<=15; ++j) {
printf( "%2x ", read_eeprom( i*16+j ) );
}
printf("\n\r");
}
printf("\r\nLocation to change: ");
address = gethex();
printf("\r\nNew value: ");
value = gethex();
write_eeprom( address, value );
} while (TRUE);
} |
The reult is
EEPROM:
01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01
01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01
01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01
01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01
Location to change: 02
New value: 65
EEPROM:
65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65
65 65 65 65 65 65 65 65 65 65 65 65 65 65 65
65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65
65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65
I don't understand why all addresses are changed. And when power off all data is 00. How can i do?. Please give some suggestions to me. Thank you. |
One obvious suggestion, that has not been mentioned, is have you read back the write protection bits from the chip itself?.
Once these are set, they cannot be cleared, so if the chip has them set, having the 'noprotect' option selected, will still leave them set. To clear these, requires a full 'erase' of the chip, in a 'high voltage' programmer (they won't clear using LVP).
You would see exactly the behaviour described, if both read, and write protection was enabled on this memory area, since when you try to read the memory, the data register would contain the last value used in the failed 'write'....
Some chips did come from the factory with the protection bits set, and this was the cause of quite a string of posts here a couple of years ago.
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
|