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; } } }
The uart_Rx() receives a character and stores it in a local variable and at the end return that local variable to the function. I have used the timer to control the execution time. The new problem which I am facing is that my UART is not able to change baud rates as soon as a break is appeared in the loop. Following is my code to read character. Please advise if I am doing anything wrong.
char read() {
flag0=0; timer0_init(); timer_count =0; uart_rxChar();
while(1) {
if(timer_count<300) {
if(uart_RxChar()>=97 && uart_RxChar()<=122) {
uart_TxChar('k');
if(timer_count>=299) {
LPC_GPIO2->FIOCLR=1<<13; Glow_GreenLED(); delay_ms(100); flag0=1;
}
else {
Glow_RedLED(); LPC_GPIO2->FIOCLR = 1<<8; break;
else if(timer_count>300) {
LPC_GPIO2->FIOCLR = 1<<8; Glow_RedLED(); delay_ms(100); LPC_GPIO2->FIOCLR = 1<<13; break;
} } }
//UART Receiving Function
char uart_RxChar() {
while(util_IsBitCleared(LPC_UART0->LSR, SBIT_RBR)); //Wait till data is received char data = LPC_UART0->RBR; return data;
As was previously brought to your attention
if(uart_RxChar()>=97 && uart_RxChar()<=122) // Reads up to TWO characters
You also need to pay attention to the instructions for posting source code.
To spell it out: www.danlhenry.com/.../keil_code.png