Topic : RC51 : DPTR error on array access

Forum : 8051

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

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

Post Information Post
July 13, 2007 - 11:05am

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 {
while (test[i] != 0);



for (;;)

The output is:

USBC test V1.04
1234567st V1.04

instead of

USBC test V1.04

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.

July 13, 2007 - 11:09am

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.