|
|
View previous topic :: View next topic |
Author |
Message |
Guest Guest
|
write_eeprom w/16F877 |
Posted: Mon Jun 14, 2004 11:48 pm |
|
|
Hi -
I wish to write constants to the EEPROM of the 16F877, but not use the #ROM directive if I can help it. I want to use the "write_eeprom" command (PCM 3.185). However, whenever I use the write_eeprom command in my main() function [for example: write_eeprom(1, 11) to test the command], I get the error "A numeric expression must appear here" on the line following the write_eeprom command. I have turned off all the relevant fuses I believe.
For what its worth, testing the read_eeprom command gives me the same (or similar) error.
Do I need to issue other setup commands to "enable" use of the eeprom? This should be easier than it is getting to be.......
Thank you for comments. |
|
|
Haplo
Joined: 06 Sep 2003 Posts: 659 Location: Sydney, Australia
|
|
Posted: Tue Jun 15, 2004 4:16 am |
|
|
There are no special setup steps needed to activate the EEPROM. Post your code so we can take a look at it. |
|
|
rnielsen
Joined: 23 Sep 2003 Posts: 852 Location: Utah
|
|
Posted: Tue Jun 15, 2004 8:36 am |
|
|
This is what I use to initialize a set of variables. If a button (input) is pressed upon powerup, I have certain default values written to the onboard eeprom.
Code: |
if(!input(PIN_B2)) // initialize the onboard eeprom to default values
{ // this needs to be done after the MCU is first programmed
write_eeprom(0x00, 0x50);
write_eeprom(0x01, 0x06);
write_eeprom(0x02, 0x05);
write_eeprom(0x03, 0x1E);
write_eeprom(0x04, 0x03);
write_eeprom(0x05, 0xFF);
write_eeprom(0x06, 0x00);
write_eeprom(0x07, 0x05);
write_eeprom(0x08, 0x00);
write_eeprom(0x09, 0x00);
write_eeprom(0x0A, 0x00);
write_eeprom(0x0B, 0x00);
write_eeprom(0x0C, 0x00);
write_eeprom(0x0D, 0x00);
write_eeprom(0x0E, 0x00);
write_eeprom(0x0F, 0x00);
}// end of if(!input)
|
Simple as that. Just make sure that you are not trying to write a value above the physical address of the eeprom.
I just thought of this too, the error is most likely just above where the compiler says the error is. It has a tendency to do that. Try looking a few lines 'UP' the code to see if you messed up something there.
Ronald |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Jun 15, 2004 12:19 pm |
|
|
Quote: | I want to use the "write_eeprom" command (PCM 3.185). However,
whenever I use the write_eeprom command in my main() function [for
example: write_eeprom(1, 11) to test the command], I get the error
"A numeric expression must appear here" on the line following the
write_eeprom command. |
I installed PCM vs. 3.185 and compiled this test program.
It compiled OK, with no errors. I suggest that you
re-install the compiler (just to be sure), and then try this program.
#include <16F877.h>
#fuses XT, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock = 4000000)
//=========================================
void main()
{
write_eeprom(1, 11);
while(1);
} |
|
|
Guest Guest
|
write_eeprom |
Posted: Tue Jun 15, 2004 2:18 pm |
|
|
PCM (and others):
Thanks.
Yes, I also wrote a really simple program like you did and I had no problems. The compiler didn't squawk and my data was in the EEPROM locations I specified. This is how I anticipated the command would work.
I don't have the code here with me now that bombed out when it encountered the "write_eeprom" command. That program has lots of defines and other stuff in it. However, when I get home I'll try again to recreate the problem (shouldn't be a problem....) and post it.
Thanks again! |
|
|
|
|
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
|