C166 Var verses immediate as index value

Hi All, I'm having a real hard time coming up with a reason why using a local var as an index into a struct fails but that same line with an immediate value specified works properly. Here's what I mean..

void main(void)
	{
	unsigned char cTemp, cValue;

// Do whats required to get under way.
//----------------------------------------------------------------------------
 	MAIN_System_Init();


// Endless While loop that the micro runs forever (hopefully).
//----------------------------------------------------------------------------
	while(gcTRUE)
		{
		cValue = 0x0C;

		cTemp = *port[0x0C].lsr;
		cTemp = *port[0x0C].txrx;

		cTemp = *port[cValue].lsr;
		cTemp = *port[cValue].txrx;

		}
	}

The first two reads to cTemp work properly (with the value 0x0C specified) but the following two reads using the cValue variable as the index fail? BTW, The reason that I say they fail is that the reads should generate an external bus read to a uart register. The first two reads generate a chip select and the second two do not. I've tried changing compiler optimizations and options but I'm running out of ideas. I'm using ver 4.20c of the C compiler and version 4.20 of most everything else. Any suggestions would be really appreciated. Thanks. ~Tim

Parents
  • Thanks for the replies. The struct is declared as volatile and I had reduced optimization all the way to zero with no change. After a day of beating on it and talking to Boniface at Keil I decided on a whim to just create a new project reusing in the exact same source code files and that cured it. I was suspicious of hardware (i.e. external ram) problems causing this but no matter which module I put those 4 lines of code in the result was the same (no external read for the second two). Thanks again for the replies..

    ~Tim

Reply
  • Thanks for the replies. The struct is declared as volatile and I had reduced optimization all the way to zero with no change. After a day of beating on it and talking to Boniface at Keil I decided on a whim to just create a new project reusing in the exact same source code files and that cured it. I was suspicious of hardware (i.e. external ram) problems causing this but no matter which module I put those 4 lines of code in the result was the same (no external read for the second two). Thanks again for the replies..

    ~Tim

Children
More questions in this forum