0

我正在为 LPC2148 使用 NEX 机器人板。我发现下面的代码行有一个非常奇怪的问题。

//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);
}

执行此代码时,我看到一个空白显示。我注意到问题出在最后一个 convertLowerNibbleToASCIIValue 函数调用上。它应该是:

temp2 =   convertLowerNibbleToASCIIValue(temp2 );

但是由于这一行错误,为什么整个显示都是空白的?只有最后一个函数 diaplayInRow1WithPosition 应该有麻烦吧?即使更改了上面的行,我也得到了空白显示。所以我将包含最后一个 convertLowerNibbleToASCIIValue 的那行替换为

temp2 =   convertLowerNibbleToASCIIValue(PLLStatus>>8);

最后我得到了正确的显示。

无法消化问题。任何人都可以帮忙吗?我需要的主要答案是,如果一行有问题,为什么前面的行没有正确执行?我正在使用 Keil 编译器和任何编译器依赖项?没有编译错误。如果类型等有问题,整个程序会损坏吗?

4

2 回答 2

0

比您的“整个程序不起作用”更有可能是:

  • 显示数据被缓冲,程序在缓冲数据到达显示器之前崩溃,
  • 或者简单地说 的值PLLStatus是不可显示的并且具有使显示器空白或可能完全停止正常工作的效果 - 它可能不是可打印的字符,并且我们没有得到有关显示硬件或其 API 的信息,所以效果垃圾输入未定义。
于 2015-04-11T23:19:12.333 回答
0

最后发现问题出在Keil编译器上。如果我添加一个额外的虚拟行(可能是任何赋值语句),代码就可以了!!!某处正在发生一些优化,但无法确定在哪里。无论如何,我现在有工作。如果不起作用,请添加一个虚拟对象,如果不需要,请再次删除!!!!

于 2015-04-22T19:10:34.213 回答