This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Break condition in while loop

Following is my program. I am trying to read characters at different baud rate and if no character is received within 10 seconds I want to break out of the loop and similarly if any character other than alphabets is received, I again want to break out of the loop? How can I do that. Please guide me.

char read()
{ while(1) { delay_ms(10000); break;

if((uart_RxChar() >= 65 && uart_RxChar() <= 90) || (uart_RxChar() >= 97 && uart_RxChar() >= 122)) { uart_TxChar('k'); Glow_GreenLED(); } else { Glow_RedLED(); break; } }
}

Parents
  • 1. Learn how to insert code in post.
    2. uart_RxChar() >= 122 <- should be uart_RxChar() <= 122
    3. I understand that "uart_RxChar()" read character from UART. But - you read it 4 times.
    After first comparsion (uart_RxChar() >= 65) character (if was received) will be cleared.
    So you have to create local variable to get it works:

    char data;
    ...
    in loop
    data = uart_RxChar();
    if((data >= 65 && data <= 90) || (data >= 97 && data <= 122)) {
    

    4. 65, 90 - what's this? Of course I know but you'll forget in less than week. Why you don'y use 'A', 'Z', etc?

Reply
  • 1. Learn how to insert code in post.
    2. uart_RxChar() >= 122 <- should be uart_RxChar() <= 122
    3. I understand that "uart_RxChar()" read character from UART. But - you read it 4 times.
    After first comparsion (uart_RxChar() >= 65) character (if was received) will be cleared.
    So you have to create local variable to get it works:

    char data;
    ...
    in loop
    data = uart_RxChar();
    if((data >= 65 && data <= 90) || (data >= 97 && data <= 122)) {
    

    4. 65, 90 - what's this? Of course I know but you'll forget in less than week. Why you don'y use 'A', 'Z', etc?

Children
No data