We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
I have a problem that i cannot solve. I need to compare two bit values. Lets say: bit Low = 0; bit High = 1; But I get some really strange results if I try to compare both of them: Low == High will result in a 0 Low != High will also result in a 0 (expected 1) High == Low will result in a 1 High != Low will also result in a 1 (expected 0) (a compare with a constant like Low == 0 will work correctly) It semms that I allways get the value of the first bit, but not the value of the comparison. Same here with sbit operations. But the C51 User Guide tells me: ~~~ The following operations may be executed with bit-type operands: [...] Compare bit with bit or constant (==, !=) ~~~ So whats the problem here ?
I tried this:
main() { bit high = 1; bit low = 0; bit result = 0; result = high == high; result = high == low; result = low == high; result = low == low; result = high != high; result = high != low; result = low != high; result = low != low; }
Ahh.... I was testing on C51, now I see you are using C251.
Yes you are right. Your test application work correctly. But please try to enter these expressions in the output window: > high == low 1 > high == high 1 ... So there must be a bug somewhere in the parser or simulator.
You are right. I am not sure what is going on here, but just for fun I also entered:
result == 1
result == 0
If you are doing this in the debugger, you need to use the eval command if you want to evaluate an expression. Otherwise, the debugger just returns the value of the first operand. Jon