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

How to use xdata?

Hi

This is code compiled with Keil C, but not working

#include <AT89X51.H>

xdata char Index _at_ 0x00;
void Clear_DDRAM(char index);

void main(void)
{
Clear_DDRAM(0x00);
while(1);
}

void Clear_DDRAM(char index)
{
int a;
for(a=0;a<65536;a++)
{
P3_4=0; //IOCS=0;
P3_1=0;
P3_0=0;
P1_0=0; //Reset=0;
Index=index;
P3_4=1; //IOCS=1;
Index=Index+a;
}
}

The xdata has 64K address range.
Here is my queation:
How to series to write data(0x00) into next address(Star address at 0x00). The assembly code is "INC DPTR" so have any instruction like it in keil C.

Parents
  • Hsu,

    I think people are having a hard time understanding your question. It looks like you are attempting to write a routine to initialize your xdata space. It looks like you want a function that will take a value passed in, and then write that value to every location in xdata. For instance, you want the call:

    Clear_DDRam(0x00)

    to fill the whole xdata address space with zeroes. Is that right? If so, your code is very confused. Maybe try something like this:

    void Fill_DDRAM(unsigned char value);
    
    void main(void) {
       Fill_DDRAM(0x00);
       while(1);
    }
    
    void Fill_DDRAM(unsigned char value) {
       unsigned char xdata * data Index;
       int data loopcount;
       Index = 0x0000;
       P3_1 = 0;
       P3_0 = 0;
       P1_0 = 0;
       for (loopcount = 0; loopcount < 65535; loopcount++) {
          P3_4 = 0;
          *Index = value;
          P3_4 = 1;
          Index++;
       }
       *Index = value;  //Take care of last location
    }
    

    Note that I've changed your loop. The loop as you wrote it is an infinite loop. An in will ALWAYS be less than 65536. I have changed my loop to "<65535" and then took care of the last location outside the loop. It's ugly, but you get the idea.

    Hope that helps.

Reply
  • Hsu,

    I think people are having a hard time understanding your question. It looks like you are attempting to write a routine to initialize your xdata space. It looks like you want a function that will take a value passed in, and then write that value to every location in xdata. For instance, you want the call:

    Clear_DDRam(0x00)

    to fill the whole xdata address space with zeroes. Is that right? If so, your code is very confused. Maybe try something like this:

    void Fill_DDRAM(unsigned char value);
    
    void main(void) {
       Fill_DDRAM(0x00);
       while(1);
    }
    
    void Fill_DDRAM(unsigned char value) {
       unsigned char xdata * data Index;
       int data loopcount;
       Index = 0x0000;
       P3_1 = 0;
       P3_0 = 0;
       P1_0 = 0;
       for (loopcount = 0; loopcount < 65535; loopcount++) {
          P3_4 = 0;
          *Index = value;
          P3_4 = 1;
          Index++;
       }
       *Index = value;  //Take care of last location
    }
    

    Note that I've changed your loop. The loop as you wrote it is an infinite loop. An in will ALWAYS be less than 65536. I have changed my loop to "<65535" and then took care of the last location outside the loop. It's ugly, but you get the idea.

    Hope that helps.

Children