【发布时间】: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 的状态。