【发布时间】:2016-06-24 12:25:17
【问题描述】:
我正在使用 dsPIC 对 C 进行一点编程,我发现了一个小问题,我不知道它为什么或如何发生。 MPLAB 编译器 C30
我有这个代码:
int Function1(){
.
.
.
while(1){
.
.
.
P1 = EPC96_1[18]; //Here the value of P1 = 0xB6
P2 = EPC96_1[19];
CRC_CCITT(EPC96_2, 18); //in this function CRC_1 is calculated also CRC2
if(P1 != CRC_1){ //In the calculation of CRC_1 it comes always 0xB6
P1++; //Both values P1 and CRC1 are the same, stil it
if(P2 != CRC_2) //comes here and continues with the break
break;
}
}
return 1;
}
//end of my function, return to main code
----对不起,我没有指定,假设不进入if,!=应该是这样的,因为我希望程序做的是两个变量相等时,它应该返回到while(1) 开始。----
我在 MPLAB (8.92) 的 Watch 上查找了变量,它们是相同的。我不认为问题出在代码之前或之后或任何其他地方,但我可能是错的。 有没有人在你体验期间发现了同样的问题?
感谢您的宝贵时间。
【问题讨论】:
-
你说
P1是0xB6,而CRC_1也是0xB6。在这种情况下,P1 == CRC_1和if-statement 将不会被遵循(它有!=)。 -
CRC_1是如何通过CRC_CCITT()函数设置的?你的意思是CRC_1 = CRC_CCITT(EPC96_2, 18)?还是全局变量? -
根据我的经验,像这些奇怪的问题是由于我自己的错误造成的。我永远不会质疑编译器,除非两个不同的编译器表现出不同的行为(这非常很少见)。
标签: c if-statement mplab dspic