This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

protecting some values while changing the battery

i m working on a project with 89c51rd2.

my problem is how to store some datas in memory...

a passwoed for example,
i store a defult value for the password when i programming.
and i want the user can change the password.
but if the user shuts down the device or wants to change batteries
then the user works the device again, the password will take the default value again.

how can i solve this?
im using C language with keil.

i cant store any values in code memory. can the data memory remember the value?

Where is the 8051's static memory?

i want to select an address an store the password there. and i wont use a default value.
But the problem is which memory of 8051 should i use, and how can i use it.

i wanna select an address and when program starting up i will check that address, if there is no value, i will store 1234 value into there as password. when user wants to change the password i will change the value of that address.

well can i select an address in code segment(or any memory space which dont forget the value) and how can i store a value into there?
eg. i wanna store a byte to FFF0 address in code segment. is it possible?

  • i was trying for a week. but no step i took.
    i saw many sources. and i found some helps.

    Keil clears all memory spaces with the file "STARTUP.A51" while starting up the device.
    Somebodies told that if i modify this file as i want, keil will not clear the memory while starting up.

    But nobody told how to do it. :D
    i copy the STARTUP.A51 file under C51/LIB. and paste under my project directory. And i add that file to my source group. i want to modify it.
    my problem is: Which changings should i do on it?
    if anybody knows, please helpp...

  • You say you have tried for a week? Tried what? Random experiments or sitting and thinking about the problem?

    If you tell the Keil tools that your processor has 10 bytes less memory than it really has - how do you then expect the Keil tools to "know" to clear these extra 10 bytes?

    If you real the Keil documentation, you will also find documentation how to create variables that are not initialized on startup.

    But the above only affects clearing of variables if you reset the processor. All variables in RAM loses their content when the processor loses the power supply. So how did you plan to supply your processor when it isn't powered?

    For processors that _can_ write to flash (which it seems your processor does support, according to other posts), it is possible to save state in flash for an indefinite time. But that requires one of two things:
    - that you change the value so seldom that you don't wear out the flash. Flash memory only supports a limited number of write/erase cycles.
    - that you can detect a power loss and have enough buffer power that you can keep the supply voltage within nominal values while you save RAM contents to flash. This spare power requires hardware support.

    For procesors that can write to EEPROM, you get more options. Since EEPROM normally allows you to write to single cells, you can reduce the wear by cycling between multiple memory cells. So yuou may be able to write every change directly to the EEPROM. Or you can do the same as with flash - detect a power loss and run on spare power while storing to EEPROM.

    Or you may look at ways to feed the processor from batteries or a large enough supercap, while you make sure that the processor switches to lowest possible power mode. Just to have the RAM cells powered.

    Or you may look at external memory like FeRAM - a technology like EEPROM but with faster write cycles and without need to care about wear from multiple writes. Lots of code that shows how to interface an EEPROM using I2C or SPI. Same code will support an FeRAM that is connected using I2C or SPI.

    So what you are saying is: No one have _given_ you a turn-key solution. You have been given suggestions, but you have spent a week on your own without looking closer at already given suggestions. The actual details have been discussed in many threads on this site. And they are possible to find using Google. Can you give one single good reason why _we_ should find the references for yuo? Or why _we_ should duplicate the information in this thread instead of having you locate the original threads?

  • Keil clears all memory spaces with the file "STARTUP.A51" while starting up the device.
    Somebodies told that if i modify this file as i want, keil will not clear the memory while starting up.

    But nobody told how to do it.
    if you can not figure that out, go back to basics

    anyhow, what does that have to do with your problem, RAM is lost during battery change

    do not try to run before you have even learned how to crawl

    Erik

  • No. Keil provides you with a default STARTUP.A51 file, where the default action is to clear memory on startup.

    "Somebodies told that if i modify this file as i want, keil will not clear the memory while starting up."

    It's nothing to do with Keil - you can modify the source code as you wish!

    "But nobody told how to do it"

    Please read the manual: http://www.keil.com/support/man/docs/c51/c51_ap_startup.htm

  • More commonly known as just "FRAM" ?

  • Please read the manual: http://www.keil.com/support/man/docs/c51/c51_ap_startup.htm

    i looked this many times.
    and this: http://www.keil.com/support/docs/374.htm
    and some others.

    i did some following changings in startup.a51

    XDATASTART      EQU     7FFFH
    XDATALEN        EQU     1H
    

    Nothing changed!

    so i decided to use an external memory as Westermark pointed

  • What were you hoping to achieve by those changes?

    What change(s) were you expecting?

    What tests did you do to confirm that nothing changed?

  • i built a 0-F counter to try it. i used a button, 4 leds and a AT89C51RC2.

    here is the codes.

    #include <89c51rd2.h>
    #include <absacc.h>
    
    #define yukari P1_0
    #define cikis P2
    
    int xdata sayi _at_ 0xF1;
    
    void main()
    {
    
       yukari = 0;
       sayi = sayi&0x000F;
       cikis = sayi;
    
    //      DBYTE [0x0002] = 5; // 0002 h adresli data bellege 5 bilgisini yaz
    //      Oku = CBYTE [0x0002]; // 0002 h adresli code bellekten 1 byte oku
    
    
       while(1)
       {
              if (yukari)
              {
                     while(yukari);
                        if(sayi<15)
                               sayi++;
                else
                               {
                                      sayi = 0;
                               }
                               cikis = sayi;
              }
       }
    }
    


    i programmed the chip and placed it to the circuit on breadboard.
    i pushed the button 5 times and the leds showed 0101.
    i removed the power and started again.

    i was hoping; leds keep showing 0101 when i started up the device again. but they didnt, they started to show 0000.

  • "i was hoping; leds keep showing 0101 when i started up the device again"

    What made you think that was even possible - let alone likely??!

    I thought you said you understood the meaning of "volatile"...??

  • RAM keeps the contents while _powered_.

    Making the startup code not clear RAM is something that is done when you reset the processor without removing the power, and want to keep the original contents of some variables.

    You either needs backup power to the RAM, or you need to use non-volatile memory. Your PC will not remember the RAM contents if you remove any battery + power coord. That is expected behaviour and the main difference between the primary memory (RAM) and the hard disk (potentially using flash memory).

  • Many people here said that is possible. but i couldnt do.

    i understood. So i will place a non-volatile memory on my pcb.

  • RAM keeps the contents while _powered_.

    Making the startup code not clear RAM is something that is done when you reset the processor without removing the power, and want to keep the original contents of some variables.

    You either needs backup power to the RAM, or you need to use non-volatile memory. Your PC will not remember the RAM contents if you remove any battery + power coord. That is expected behaviour and the main difference between the primary memory (RAM) and the hard disk (potentially using flash memory).

    so many people had given advices about this thread.
    But u told the most helpfull things.

    Thanks you. i will place a non-volatile memory onto my pcb.

  • Said what is possible?

    It has been quite clearly stated that you need either a backup power source or a non-volatile memory.