Topic : RC51 : DPTR error on array access

Forum : 8051

Original Post
Post Information Post
May 7, 2007 - 10:35pm
Guest

RC51 gives errors when accessing arrays in this way

unsigned xdata char c;
int xdata z[c];

z[c] = func();
z[c] = z[c] - expr( z[c] ); e.g z[c] = z[c] - (z[c] / 16); <---- this expression fails

The mistake is that DPTR is offset by 1 byte, reading z[c] from 2 adjacent words in z[]

A workaround is to split the offending code line with a dummy variable i.e:

n = z[c] / 16;
z[c] = z[c] - n;

The RIDE build is 6.4.43. I've sent code files and other details directly to Raisonance.

Steven Pruzina

Replies
Post Information Post
+1
0
-1
July 13, 2007 - 11:05am
Guest

There seems to be a problem with the printf() function on the Atmel 89C5131A device. The code fragment below sends correct data using putchar and incorrect data using printf.

code const char test[] = "USBC test V1.04";

void main(void)
{
int i;

PLLCON = 0x04; // disable the clock oscillator and PLL (48MHz direct clock)
CKCON0 = 0x01; // select X2 mode
set_serial(57600); // set up the UART

i = 0;
do {
putchar(test[i++]);
}
while (test[i] != 0);

putchar(0x0D);
putchar(0x0A);

printf("1234567890");

for (;;)
;
}

The output is:

USBC test V1.04
1234567st V1.04

instead of

USBC test V1.04
1234567890

Using just the printf() function, with a string pointer and without the preceding calls to putchar(), produces even stranger results.

Is this a known problem? The RIDE51 build is 6.4.37. Memory model is SMALL.

+1
0
-1
July 13, 2007 - 11:09am
Guest

Apologies to Steven Pruzina - this was mis-posted here and there does not seem to be any way to edit or delete it. I will re-post it to the general forum.

Campbell Kelly.