I know this may be wrong section for this but my problem is Microcontroller programming specific (AVR mostly)!
I am sending bytes between two AVR atmega8 using Uart where each bit in the byte stands for something and only one bit is 1 in each byte sent
So if I want to check, say for example, 5th bit in the received byte then if write it as follows:
short byte=UDR;
if(byte&(1<<5))
{
// do stuff for bit 5
}
Then it works fine always
BUT, if I write it as this:
short byte=UDR;
if(byte==0b00100000)
OR
short byte=UDR;
if(byte==0x20)
Then it won't work , also it fails if I use Switch-case instead of if-else I can't understand the problem, does the compiler interprets it as signed no and 7th Bit as sign? or something else? The compiler is AVR-gnu from AVR studio 5
If someone asks I also have LEDs on the receiver that shows received byte and so I know the byte received is correct but for some reason I cannot compare it for conditions! still can there some noise that causes bits to be misunderstood by the Uart and thus changing the actual byte received?
Help !
LOOK OUT EVERY ONE
Something here is like PARANORMAL
Finally I have cornered the area of problem
I added 8 LEDs to represent the bits of received bytes and here's what I found:
The LEDs represent (1<<5) as 0b00100000 that's ok as its what I sent
BUT
The other LEDs (excluding the 8) assigned to glow on receiving 0b00100000 does not glow!
FTW MAN!
I'm damn sure the received byte is correct ..but something's wrong with if-else and switch-case comparision