#include <avr/io.h>
#include <avr/interrupt.h>
#include <stdint.h>

char c;

ISR(USART_RXC_vect) {
	if (UCSRA & (1<<FE|1<<DOR|1<<PE)) {
		c=UDR;
		c='?';
	}
	else {
		c=UDR;
	}
	UCSRB&=~(1<<RXCIE);
	UCSRB|=(1<<UDRIE);
}

ISR(USART_UDRE_vect) {
	static uint8_t echo=0;
	UDR=c;
	echo++;
	if (echo==2) {
		echo=0;
		UCSRB|=(1<<RXCIE);
		UCSRB&=~(1<<UDRIE);
	}
}

int main() {
	// 9600-7-E-1
	UCSRA=0x00;
	UCSRB=0x98;
	UCSRC=0xA4;
	UBRRH=0;
	UBRRL=23;
	sei();
	while(1);
	return 0;
}
