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 CCS Technical Support

Default value of eeprom memory

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



Joined: 24 May 2007
Posts: 97

View user's profile Send private message

Default value of eeprom memory
PostPosted: Wed Jul 18, 2007 8:57 am     Reply with quote

Hello,

I am trying to implement a code which will set some default values in eeprom locations on the 16F88 if previously nothing been set.

The eeprom locations are defined like this:
Code:

#Define Close      60
#Define Normal    50
#Define Far         40
#Define Low         9
#Define Medium    7
#Define High        5
#Define EESens    0
#Define EEDist     1
#Define EETime    2


Then I check if any values have been written to it previously if it hasn't then I put in a default value:

Code:

   Sensitivity = read_eeprom(EESens);
   If (Sensitivity == 255) {
      Sensitivity = Medium;
      Write_eeprom(EESens,Sensitivity);
   }
   ETime = read_eeprom(EETime);
   If (ETime == 255) {
      ETime = 40;
      Write_eeprom(EETime,ETime);
   }
   Dist = read_eeprom(EEDist);
   If (Dist == 255) {
      Dist = Close;
      Write_eeprom(EESens,Dist);
   }


However I am not sure that these locations by default contain 255. Later down in the execution of the code I have a feeling that these default values are not set properly.

Can somebody please confirm if this assumption is correct or not, an if it is not, than what is the default value of these eeprom locations?

thanks, Ox.
Bill Boucher



Joined: 04 Feb 2005
Posts: 34
Location: Chatham,ON,CA

View user's profile Send private message Send e-mail Visit poster's website

PostPosted: Wed Jul 18, 2007 9:09 am     Reply with quote

Dude, you can put the default eeprom values into your C source using the #ROM directive. You do not have to use up your valuable program memory to run code upon powerup to test for and install defaults. You might have to do that to "restore" defaults later after they've been changed, but if all you want to do is program your chips with default data, then do it like this...

Code:

// The following initializes the locations of the data EEPROM
//  using the #ROM directive
#if defined (__PCM__)
#rom 0x2100={30,0,0x58,0x02,0x20,0x1C,50,0,0xEC,0,8,0,50,0,248,0,38,0,0x58,0x02,0,0}
#elif defined(__PCH__)
#rom int 0xf00000={30,0,0x58,0x02,0x20,0x1C,50,0,0xEC,0,8,0,50,0,248,0,38,0,0x58,0x02,0,0}
#endif
oxxyfx



Joined: 24 May 2007
Posts: 97

View user's profile Send private message

PostPosted: Wed Jul 18, 2007 9:34 am     Reply with quote

thanks, this probably will work. Now, does this load the eprom every time I boot the Pic? I hope not, because I may change the values using the menu, and I want the values I set to be sitting permanently in my eprom.

Also I noticed why my menu is not working, maybe you have an idea what's going on.

In the menu I enter, and I have the Pic beep me the value of a certain eprom location. after that it gives me 3 or 4 - depending on the menu - choices to choose from and I can set any of these by pressing a button after the beep or beeps for the respective choice have sounded.

Now, once I set a value based on the menu, and I go back again, I get beeped many more times than the value should be. Here is the program:

Code:

         Delay_ms(1500);
         Longbeep();
         Delay_ms(300);
         Shortbeep();
         Delay_ms(1500);
         If (!Input(M_Button)) {
            EndBeep();
            Sensitivity = read_eeprom(EESens);
            Delay_ms(500);
            If(Sensitivity == Low) ShortBeep();
            Else If(Sensitivity == Medium) {
                 ShortBeep();
                 Delay_ms(300);
                 Shortbeep();
            }
            Else If (Sensitivity == High) {
                 ShortBeep();
                 Delay_ms(300);
                 ShortBeep();
                 Delay_ms(300);
                 ShortBeep();
            }
            Else If (Sensitivity == VHigh) {
                 ShortBeep();
                 Delay_ms(300);
                 ShortBeep();
                 Delay_ms(300);
                 ShortBeep();
                 Delay_ms(300);
                 ShortBeep();
            }
            Else {
                  For (iX = 1; iX < Sensitivity; iX++){
                     Shortbeep();
                     Delay_ms(250);
                  }
               }
         }
         Delay_ms(2000);
         Over = 0;
            While(Over == 0){
                  Shortbeep();
                  Delay_ms(1500);
                  If (!Input(M_button)) {
                     EndBeep();
                     Delay_ms(500);
                     Write_eeprom(EESens,Low);
                     Over = 1;
                  }
                  Else {
                       ShortBeep();
                       Delay_ms(300);
                       ShortBeep();
                       Delay_ms(1500);
                       If (!Input(M_button)) {
                           EndBeep();
                           Delay_ms(500);
                           Write_eeprom(EESens,Medium);
                           Over = 1;
                       }
                       Else {
                          ShortBeep();
                          Delay_ms(300);
                          ShortBeep();
                          Delay_ms(300);
                          ShortBeep();
                          Delay_ms(1500);
                          If (!Input(M_button)) {
                              EndBeep();
                              Delay_ms(500);
                              Write_eeprom(EESens,High);
                              Over = 1;
                          }
                          Else {
                                ShortBeep();
                                Delay_ms(300);
                                ShortBeep();
                                Delay_ms(300);
                                ShortBeep();
                                Delay_ms(300);
                                ShortBeep();
                                Delay_ms(1500);
                                If (!Input(M_button)) {
                                    EndBeep();
                                    Delay_ms(500);
                                    Write_eeprom(EESens,VHigh);
                                    Over = 1;
                                }
                          }
                       }
                  }
            }


Here if I write the eprom with let's say Low which is defined to be 9, after I go out and come back, I end up in the Else with the for cycle and it beeps me 49 times. Why is that? Why isn't it writing the value 9 in the eprom location I ask for?

Thanks, ox.

Than
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Wed Jul 18, 2007 10:03 am     Reply with quote

Quote:
Here if I write the eprom with let's say Low which is defined to be 9, after I go out and come back, I end up in the Else with the for cycle and it beeps me 49 times. Why is that? Why isn't it writing the value 9 in the eprom location I ask for?
Your code is not complete so we can only guess.
How did you define Low? Sounds like you are mixing the ASCII-value and binary values.
Code:
#define Low '1'    // Will give you 49 beeps
#define Low  1     // Will generate a single beep
oxxyfx



Joined: 24 May 2007
Posts: 97

View user's profile Send private message

PostPosted: Wed Jul 18, 2007 10:52 am     Reply with quote

Thank you. The definitions are in the first post of the thread. I defined them correctly as a binary - not an ASCII.
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Wed Jul 18, 2007 11:46 am     Reply with quote

How do you know it are 49 beeps? With 4 beeps a second you have to count really fast.

Could it be you are hearing 60 beeps?
Code:
#Define Close      60

...

      Dist = Close;
      Write_eeprom(EESens,Dist);       <-- looks like a bug. Writing to EESens, should likely have been EEDist
oxxyfx



Joined: 24 May 2007
Posts: 97

View user's profile Send private message

PostPosted: Wed Jul 18, 2007 12:07 pm     Reply with quote

Thanks for pointing that out... Copy and paste bug....

Ox.
Bill Boucher



Joined: 04 Feb 2005
Posts: 34
Location: Chatham,ON,CA

View user's profile Send private message Send e-mail Visit poster's website

PostPosted: Wed Jul 18, 2007 7:11 pm     Reply with quote

oxxyfx wrote:
thanks, this probably will work. Now, does this load the eprom every time I boot the Pic? I hope not...


No, the programmer will program the eeprom when you first program your chip. After that, the data is sitting in eeprom. If your program then writes new values at runtime, they'll stay there forever as you wanted.
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