【问题标题】:Entire program not working due to one logical error由于一个逻辑错误,整个程序无法运行
【发布时间】:2015-04-11 15:00:51
【问题描述】:

我正在为 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 编译器和任何编译器依赖项?没有编译错误。 如果类型等有问题,整个程序会损坏吗?

【问题讨论】:

  • 如果没有这些函数的代码,其他任何人都很难分析。您可能会做的事情是比较两个版本的列表文件或反汇编,看看有什么变化。或者,您可以在断点调试器下运行,或者添加监控输出(例如串行端口)或在程序中可以使用范围监控的点更改 GPIO 的状态。

标签: arm embedded lpc


【解决方案1】:

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

  • 显示数据被缓冲,在缓冲数据到达显示之前程序崩溃,
  • 或者只是 PLLStatus 的值不可显示,并且具有使显示器空白或可能完全停止正常工作的效果 - 它可能不是可打印字符,并且我们没有得到有关显示硬件的信息或它的 API,所以 garbage-in 的效果是不确定的。

【讨论】:

    【解决方案2】:

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

    【讨论】:

      猜你喜欢
      • 2016-04-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-08-26
      • 1970-01-01
      • 2014-10-11
      • 1970-01-01
      相关资源
      最近更新 更多