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

XDATA Question

Hi,
I have a loop

for (address = 1; address <= 5; address ++)

ram_ptr[address] = 0xFA:

where unsigned char xdata *ram_ptr = 0x0000;
and unsigned int address;

Somehow when i watch the simulation the address never increments and it always write FA in the same address 0x0000. I have also tried using XBYTE[address] to no use.
Any solution to my problem would be greatly appreciated

  • I'm not sure I understand what you are trying, but to increment an XDATA location with XBYTE, increment an offset from the base address.

      #include <absacc.h>
      
      #define address 0x0000
      
      void main(void)
      {
        unsigned char xdata i;
        while(1)
        {
          for(i = 1; i <= 5; i++)
          {
            XBYTE[address+i] = 0xFF;
          }
        }
      }
    

    Brad

  • Doesn't seem to work. I don't see any reason why i should be declared as an xdata. I just want to initialize my external RAM which is mapped on the xdata address space.
    So i declared *ram_ptr to point to 0x0000 (start address) and then i wanted to do a for loop and initialize the initial few locations. So i used ram_ptr[address] and also XBYTE.

  • Other than you did not show us the definition of address (which I dummied up for my simulation), your code works just fine. That is, 0xFA is stored into XDATA locations 0x0001-0x0005 and address increments from 1 through 6.

    Are you sure you are watching the correct memory space in the simulator (in your memory window specify "x:0" as the address)? Have you set a Watch on address? Methinks you might not be using the simulator correctly.

  • "I just want to initialize my external RAM which is mapped on the xdata address space."

    This is already handled by startup.a51

  • Yes, in simulator everything seems to work fine, when i do real simulation with DW8051 it doesn't seem to work right. Let me give you an example.
    This works
    unsigned char xdata *ram_ptr = 0x0000;
    and then
    *ram_ptr = 0xAA;
    ram_ptr += 0x01;
    *ram_ptr = 0xBB;
    ram_ptr += 0x01;
    *ram_ptr = 0xCC;
    ...
    If i attempt to do the same thing using a for loop like
    for (address = 0; address <= 5; address ++)
    {
    *ram_ptr = 0xAA;
    ram_ptr += 0x01;
    }
    it somehow writes only AA to the location 0x0000 all the 6 times in the loop.

    Any reason why ?

    Thanks for your response

  • So I take it that we're talking about two different simulators here -- uVision's simulator works fine, but DW8051's (some 8051 core design tool???) simulator does not.

    You can convince yourself that there is nothing wrong with the Keil side of the toolchain by looking at the resulting assembly code and verifying that it's "doing the right thing". Then you'll have to figure out why DW8051 (or whatever) is broken. I can't help you out with that one, however.

  • Sorry about the var i confusion. When I got to XBYTE I got carried away with xdata. XBYTE is used to access xdata NOT data area.
    As Andrew and Dan pointed out, the startup.a51 will clear the data area and selected areas of xdata. Init.a51 will initialize some statics and init_tny.a51 will initialize statics defined in the small data area of some LPC type devices. See chapter 6 of C51 user guide for these routines.
    Is the DW8051 a CEIBO device or Simulator?
    Brad

  • Maybe address is located by the linker at 0x0000?
    If it is, you set address to 0xAA with your first pointer assignment and the loop stops.
    The same could have happened with your ram_ptr.