Search code examples
armembeddedlpc

Entire program not working due to one logical error


I am using NEX Robotics board for LPC2148. I find very strange problem with below lines of code.

//Prototypes
void diaplayInRow1WithPosition(unsigned char* data, unsigned char position);
void diaplayInRow2WithPosition(unsigned char* data, unsigned char position);
unsigned char convertHigherNibbleToASCIIValue(unsigned char data);
unsigned char convertLowerNibbleToASCIIValue(unsigned char data);
int main (void)
{
    unsigned char temp2;
    unsigned int PLLStatus;
    initializeAll();
    PLLStatus = PLL0STAT; 
    temp2 =   convertLowerNibbleToASCIIValue(PLLStatus);
    diaplayInRow1WithPosition(&temp2,15);
    temp2 = convertHigherNibbleToASCIIValue(PLLStatus);
    diaplayInRow1WithPosition(&temp2,14);
    temp2 = PLLStatus>>8;
    temp2 =   convertLowerNibbleToASCIIValue(PLLStatus);
    diaplayInRow1WithPosition(&temp2,13);
    return(0);
}

When this code is executed, I see a blank display. I noticed that the problem is with last convertLowerNibbleToASCIIValue function call. It should have been:

temp2 =   convertLowerNibbleToASCIIValue(temp2 );

But because of this one line error, why entire display is blank? Only last function diaplayInRow1WithPosition should have given trouble right? Even after changing with above line, I am getting blank display. So I replaced that line containing last convertLowerNibbleToASCIIValue as

temp2 =   convertLowerNibbleToASCIIValue(PLLStatus>>8);

And finally I got correct display.

Unable to digest the problem. Anyone can help? Main answer I need is if at all there is a problem in one line, why previous lines are not getting executed correctly? I am using Keil compiler and any compiler dependencies? There is no compilation error. If there is a problem with types etc, will entire program get corrupted?


Solution

  • Finally found that the issue is with Keil compiler. If I add one additional dummy line (could be any assignment statement), code works!!! Somewhere some optimization is happening, but unable to make out where. Anyway I have work around now. Add one dummy if does not work and remove again if not needed!!!