CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

write_eeprom w/16F877

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Guest
Guest







write_eeprom w/16F877
PostPosted: Mon Jun 14, 2004 11:48 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Tue Jun 15, 2004 4:16 am     Reply with quote

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

View user's profile Send private message

PostPosted: Tue Jun 15, 2004 8:36 am     Reply with quote

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

View user's profile Send private message

PostPosted: Tue Jun 15, 2004 12:19 pm     Reply with quote

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
PostPosted: Tue Jun 15, 2004 2:18 pm     Reply with quote

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!
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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