1

The following code is the code for UART receving

Char uart_receive {
  While( ! ( UCSRA & ( 1 << RXC ) ) );
  return UDR;
}

This function will not return the UDR value until the while loop breaks because its expression evaluates to zero.

My question is: When there is a byte in the receiving buffer,the RXC= 1, so the while loop will be while(1) and it will be infinite loop ,so the function will not return the UDR value.... can any one help me to understand this?

  • the form of the statement is while ( true ), not while ( 1 ) .... when the logic evaluation becomes false then the while loop exits – jsotola Oct 14 '20 at 15:21
  • The ! negates the 1 (which is a trueish value) to a false. Then the while loop exists. If the expression after the `!' evaluates to 0 that's a falsy value and the '!' negates it to true. – Peter Paul Kiefer Oct 14 '20 at 15:44
  • Ok..thank you sir... – user255471 Oct 14 '20 at 15:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.