C/regarding c....
Expert: Zlatko - 3/24/2011
Questioncan i know the discription of this coding
while ((UCSR0A & (1<<UDRE0)) == 0);
UDR0 = data;
what does USCROA mean? and also UDRO.....
AnswerHello p
The loop below
while ((UCSR0A & (1<<UDRE0)) == 0);
is trying to find a bit in UCSR0A which is set to 1. It does this by taking 1 and shifting it to the left by the amount in UDRE0.
For example if UDRE0 is 3, then 1 will be shifted to the left by 3, so, in binary
00000001
becomes
00001000
lets call that the test pattern.
The loop then does a bitwise AND of USCR0A against the test pattern
For example if OSCR0A is 11111000, then ANDing it against the test pattern will produce 00001000 because there is a 1 in both the test pattern AND in OSCR0A at the same bit position.
The loop exits as soon as the test pattern finds a 1 on OSCR0A, meaning as soon as the result of the AND is non-zero.
This type of loop is often used to find the least significant bit which is set to 1 in a memory location (in this case the location is USCR0A)
There is a problem with the loop because I see no way that UDRE0 is changed. For the loop to work properly, UDRE0 needs to be changed by some other method, maybe another thread, or some external event if it is a hardware input register.
There is no way I can be sure of the purpose of these lines without seeing the rest of the program.
Best regards
Zlatko