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

Writing variables to nonvolitile memory using xdata

Writing variables to nonvolitile memory using xdata

My MCU is ADuC841 it had (working with SDK)

62 kBytes on-chip Flash/EE program memory
4 kBytes on-chip Flash/EE data memory

I want to store variable that i get from the serial port and write them to the EEPROM then turn off, turn on the MCU and read them some how
(print the stored variable to screen = Hyperterminal)
or using interrupt that prints it to screen.

my code is working on the the simulator of keil
i see the memory window but on then target MCU
it doesn't work

My code:

unsigned char xdata large_array[20] _at_ 1500;
unsigned int  xdata timer_tick;

void INT_EX0() interrupt 0
{
    puts(large_array);
}

void main (void)
{
  while(1)
   {
    T3CON = 0x87;     // 4800
    T3FD  = 0x08;
    SCON  = 0x52;

    IT0  = 1;   // Configure interrupt 0 for falling   edge on /INT0 (P3.2)
    EX0  = 1;   // Enable EX0 Interrupt
    EA   = 1;

   puts("\nEnter string :");
   getline(large_array);   // get string from serial port
   puts(large_array); // read from memory and output to serial port
   }
}


the output of the MCU on Hyperterminal is something like all the char in ascii - "abcdefg...!@#$%^&*()..."

WHAT IS THE PROBLEM ??

Thanks in advance !!!

Mayer

Parents Reply Children
  • http://www.keil.com/support/man/docs/c51/c51_ap_xbanking.htm

    "The far memory type allows you to address special memory areas like EEPROM space or strings in code banking ROM. Your application accesses these memory areas as if they are a part of the standard 8051 memory space. Example programs in the folder C51\EXAMPLES\FARMEMORY show how to use the C51 far memory type on classic 8051 devices. If an example that fulfills your requirements is not provided, you may adapt the access routines..."

    Note that the LX51 linker/locator is required - this is not supported by BL51.

  • Andy, Hans thanks for your answers

    How can i declare my EEPROM to be access like an array

    I didn't succeed to do it with the FAR
    declaration as you said in the example - Keil\C51\EXAMPLES\FarMemory

    My EEPROM is : (working with ADUC841)

    The 4 kBytes of Flash/EE data memory are configured as
    1024 pages, each of 4 bytes.

    (4 kBytes on-chip Flash/EE data memory)

    my final purpose is to save some struct of char in the EEPROM and it can't be done (or you have some other good idea)
    with the solution that above (in the Thread)

    Thanks,

    Mayer

  • "How can i declare my EEPROM to be access like an array"

    If you want it to be directly accessed as any sort of standard 'C' variable - whether an array or something else - then you will have to use FAR - there is no other way.

    "I didn't succeed to do it with the FAR"

    Then you need to investigate the cause of your failure!

    "my final purpose is to save some struct of char in the EEPROM"

    Is it really?

    Think about it: a struct is just one for the to program handle the data - it doesn't necessarily have to be stored in that way, does it?

    A common way to handle this is to write a couple of functions: one to write to EEPROM, and one to read from EEPROM. As far as the functions (and the EEPROM) are concerned, they are just writing data - they neither know nor care whether the rest of the program treats it as a struct, or an array, or a float, or whatever...

    For an analogy, think about writing data to files, and reading data from files...

  • "one to write to EEPROM, and one to read from EEPROM"

    Which is exactly what this example does:

    http://www.keil.com/download/docs/184.asp