Hi all, I just want to ask why I cannot use this in C51:
... sbit INPUT1 = P0 ^ 0; sbit INPUT2 = P0 ^ 1; #define CHECK_INPUT ((INPUT1 << 7) | (INPUT2 << 6))
When try using it:
while(1) { ... unsigned char temp; temp = CHECK_INPUT; ... }
When compiled, the error: *** ERROR C193 IN LINE 40 OF xxx.c: '<<' : bad operand type
What should be the best thing to do? And why the error occur?
regards gee
Sorry, I forgot to say that I need the two bits, it has 4(11,10,01,00) possible values so I need to evaluate each bit and not to combine the two. That is the reason I shifted the bit to the upper nibble of a byte. Well, upper nibble doesn't matter as long as I can put the two bits in a byte.
thanks gee
So why not just take the value you can read from P0 and shift 6 steps left? Why go the route to make two 1-bit reads from the port?
That is the reason I shifted the bit to the upper nibble of a byte. Well, upper nibble doesn't matter as long as I can put the two bits in a byte.
So what was wrong with the almost painfully obvious
(P0 & 0x03)
?
Thanks Per and Hans for your very simple yet effective solution.
thanks again Gee