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
  • Hi Everyone
    I post my assembler code and use a illustration says what it is meant to say and
    hope you can clearly understand my questions?

    Assembler code
    ;------------------------------
    DDRAM_RESET:
    MOV DPTR,#0000H
    MOV R0,#00H
    MOV R1,#00H
    MOV A,#00H
    RESET1: ;reset from 0000h to FF00h
    CALL ZEROWR
    INC DPTR
    INC R0
    CJNE R0,#00H,RESET1
    INC R1
    CJNE R1,#FFH,RESET1

    RESET2: ;reset 00FFh more
    CALL ZEROWR
    INC DPTR
    INC R0
    CJNE R0,#FFH,RESET2

    RET
    ;--------------------------------------------ZEROWR: ;Write 00 to MEM(DDRAM) thru 1352
    CLR P3.4 ;MEMCS#=0,
    CLR P3.1
    CLR P3.0
    CLR P1.0 ;Ereset=0;
    MOVX @DPTR,A
    SETB P3.4 ;MEMCS#=1
    RET
    ;------------------------------------------
    Illustration:

    The data(index)=0x00
    __
    |00|Index(Address 0) | Next address
    |__| V
    |00|Index(address 1)
    |__|
    . .
    . .
    __
    |00|Index(Address 65534) | Next address
    |__| V
    |00|Index(address 65535)
    |__|

    The external of memory start address(Index)=0x00
    The next address(Index+1)=0x01

Reply
  • Hi Everyone
    I post my assembler code and use a illustration says what it is meant to say and
    hope you can clearly understand my questions?

    Assembler code
    ;------------------------------
    DDRAM_RESET:
    MOV DPTR,#0000H
    MOV R0,#00H
    MOV R1,#00H
    MOV A,#00H
    RESET1: ;reset from 0000h to FF00h
    CALL ZEROWR
    INC DPTR
    INC R0
    CJNE R0,#00H,RESET1
    INC R1
    CJNE R1,#FFH,RESET1

    RESET2: ;reset 00FFh more
    CALL ZEROWR
    INC DPTR
    INC R0
    CJNE R0,#FFH,RESET2

    RET
    ;--------------------------------------------ZEROWR: ;Write 00 to MEM(DDRAM) thru 1352
    CLR P3.4 ;MEMCS#=0,
    CLR P3.1
    CLR P3.0
    CLR P1.0 ;Ereset=0;
    MOVX @DPTR,A
    SETB P3.4 ;MEMCS#=1
    RET
    ;------------------------------------------
    Illustration:

    The data(index)=0x00
    __
    |00|Index(Address 0) | Next address
    |__| V
    |00|Index(address 1)
    |__|
    . .
    . .
    __
    |00|Index(Address 65534) | Next address
    |__| V
    |00|Index(address 65535)
    |__|

    The external of memory start address(Index)=0x00
    The next address(Index+1)=0x01

Children