#define F_CPU 8000000UL #define UART_BAUD_RATE 9600L #define UART_BAUD_CALC(UART_BAUD_RATE,F_CPU) ( (F_CPU)/(UART_BAUD_RATE*16L)-1 ) #include #include #include #include #include uint8_t uart_complete=0; char data_string[200]; int uart_putc(unsigned char c) { while (!(UCSRA & (1<>8); UBRRL= (uint8_t) UART_BAUD_CALC(UART_BAUD_RATE,F_CPU); sei(); while(1) { if (uart_complete==1) { uart_complete=0; uart_puts(data_string); } _delay_us(1); } } ISR (USART_RXC_vect) { unsigned char next_byte; uint8_t uart_str_count = 0; next_byte=UDR; if (uart_complete==0 && next_byte!='\n') { if (uart_str_count<=200) { data_string [uart_str_count] = next_byte; } else { uart_str_count=0; next_byte=0; uart_complete=1; } uart_str_count++; } else { uart_complete=1; next_byte=0; uart_str_count=0; } }