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

XRAM not cleared, variables not assigned

im using a phillips 89c668 uC with 64k on chip ROM and 8k on chip XRAM. keil has been setup to use the on chip XRAM. AUXR is set to 0. startup.a51 has been modified to include the foll

XDATASTART EQU 0H ; the absolute start-address of XDATA memory
XDATALEN EQU 1EFFH ; the length of XDATA memory in bytes.

this should clear the XRAM, however when i display the contents of a variable that i assign 0 during declaration, it shows garbage. hence neither is the XRAM being cleared, nor is the assignment during declaration taking place.

  • My guess is that you need modify startup.a51 to select internal RAM as the very first thing.

    Erik

  • And you'll need the code in INIT.A51 to perform file-scope static initialization for non-zero values.

  • And you'll need the code in INIT.A51 to perform file-scope static initialization for non-zero values
    I do not think so, if startup set XRAM to be internal, INIT should just work.

    Erik

  • "My guess is that you need modify startup.a51 to select internal RAM as the very first thing."

    Yes - Note that the memory settings in uVision do not generate any code to configure the target processor. You have to add that manually - and startup.a51 would be a very good place to do it.

  • iv modified startup.a51 as iv shown in my first post. are there any more changes i need to make??

    i got the program to work on an evaluation board using the internal ram. variable assignment is not taking place only during declaration as follows

    unsigned char InitOver[3]={0,0,0};

    the value of InitOver[0] is being set to D7. however if i assign a value to it during the program, it works fine.

    secondly, though it is working on the evaluation board, it refuses to call any functions on my final project board. i have a loop as follows:

    while (1)
    {
    MODBUS_RTU_SLAVE(&Modbus);
    }

    however the MODBUS_RTU_SLAVE function is not called. i check this by toggling P1^0 on entering the function. P1^0 is being pulled high thru a DIP switch. on the evaluation board, i have an LCD display, so i can display a value on it on entering the function which it does perfectly. on my board, the display init function is commented

  • From the C51 manual:

    The INIT.A51 file contains the initialization routine for variables that were
    explicitly initialized.
    

    From the INIT.A51 file:

    ;  INIT.A51:  This code is executed, if the application program contains
    ;             initialized variables at file level.
    
    ; This section describes the initialization data generated by C51 for
    ; explicit variable initializations (in segment ?C_INITSEC).
    ;
    ; Explicit variable initilizations at C source level are stored by C51 in
    ; the segment ?C_INITSEC.  All partial segments are combined at linker level
    ; to one segment.  The segment end value DB 0 is taken from this library module
    ; INIT.A51.
    ;
    
    

    If you use static initializers in your program, then some piece of code has to copy those static values from ROM to the RAM location of the variables. This is the job done by INIT.A51. The code in STARTUP.A51 initializes RAM to zero, which is required by the C standard for uninitialized memory.

    In this particular case, the initializer is redundant. Uninitialized memory is guaranteed to be zero anyway.

    When you are tempted to write a static initializer, you should likely ask yourself two questions: (1) is this a constant that I can leave in code space; and (2) does my program have any error handling, recover, or restart path that requires this variable to be re-initialized, other than a complete reset of the system? In either case, you probably don't want static initialization of your variable, but a different declaration or an explicit initialization routine somewhere in your own code.

  • thanks...il try doing that for the variable assignment. however the variables not getting assigned is of no significance if the function itself is not called.

    i am passing the address of a structure to the function. the contents of thi structure "Modbus" contain basic settings for my program conditional statements. these variables are being assigned.

    also doesnt the INIT.A51 procedure apply even if i use off chip xram?? because INIT.A51 was not a part of my project till now. and the program worked without a hitch

  • The physical location of the "external" RAM doesn't matter. It's called "external" because of the design of the original 8051. Often, you have "external" RAM integrated onto the same die as the processor core and sold in a single package, but as far as the processor core is concerned, it's still "external". Xdata really means "not the 128/256 bytes of directly/indirectly addressable RAM that you can only access via the DPTR by using a MOVX instruction.".

    If you have both sorts of memory, then there's likely some part-specific registers you initialize to select whether you're using the on-chip xdata or the off-chip xdata. Earlier posts discuss that.

    Since the initializer shown above is { 0, 0, 0 }, it doesn't really matter for this case if you leave out INIT.A51. The memory will be initialized to 0 by the STARTUP.A51 code anyway.

  • "If you have both sorts of memory, then there's likely some part-specific registers you initialize to select whether you're using the on-chip xdata or the off-chip xdata."

    Yes - that's why I said earlier,

    "Note that the memory settings in uVision do not generate any code to configure the target processor. You have to add that manually - and startup.a51 would be a very good place to do it."

  • thanks all u guys for helping out...started searching for the startup.a51 additions and found this:

    http://www.keil.com/support/docs/1978.htm

    solves my problem...also understood the need (or the lack of it in my case) for init.a51

    thanks once again