I am trying to receive a string from USART but failed , i want to receive char by char and store them in an array until the user enter '\n' and finally display the string to LCD , here is my code:
char REC;
void USART_Init(unsigned int BAUD )
{
unsigned int ubrr;
ubrr=F_CPU/16/BAUD-1;
/* Set baud rate */
UBRRH = (unsigned char)(ubrr>>8);
UBRRL = (unsigned char)ubrr;
/* Enable receiver and transmitter */
UCSRB |= (1<<RXEN)|(1<<TXEN)|(1<<RXC);
/* Set frame format: 8data, 1stop bit */
UCSRC = (1<<URSEL)|(3<<UCSZ0);
sei();
}
ISR(USART_RXC_vect){
REC = UDR;
}
int main(void)
{
lcd_init(20);
USART_Init(9600);
char data[10];
while(1)
{
int i = 0;
while (REC !='\n')
{
data[i++]=REC;
}
data[i]='\0';
lcd_puts(data);
}
}