#include #include #include #define USART_BAUDRATE 4800 #define BAUD_PRESCALE (((F_CPU / (USART_BAUDRATE * 16UL))) - 1) void icp_init(void); void usart_init(void); void usart_transmit(unsigned char); unsigned char usart_receive(void); volatile unsigned char sync; volatile unsigned char end; volatile unsigned int start_pulse; volatile unsigned int end_pulse; int main(void) { DDRD = 0xFE; usart_init(); icp_init(); while (1) { if (sync == 2) { usart_transmit(0xFF); } else if (sync == 1) { usart_transmit(end_pulse>>3); } sync = 0; } } ISR(TIMER1_CAPT_vect) { if (end == 0) { start_pulse = ICR1; end = 1; } else { end_pulse = ICR1 - start_pulse; end = 0; if (end_pulse > 2100) { sync = 2; } else if (end_pulse > 900) { sync = 1; } } } void icp_init(void) { // set ICP pin as input DDRB &= ~(1<>8); UBRR0L = (unsigned char) BAUD_PRESCALE; // enable receiver and transmitter UCSR0B = (1<