#ifndef F_CPU #define F_CPU 16000000UL #endif #include #include #include #define DIGIT_MASK 0x0F static const uint8_t digits[4] = {0x06, 0x5B, 0x4F, 0x66}; ISR(TIMER2_OVF_vect) { static uint8_t phase = 0; uint8_t digit = phase >> 1; uint8_t group = (phase & 1U) ? 0x70 : 0x0F; PORTB |= DIGIT_MASK; PORTD = 0; PORTD = digits[digit] & group; PORTB &= (uint8_t)~(1U << digit); phase = (phase + 1U) & 0x07; } int main(void) { cli(); UCSR0B = 0; TIMSK0 = 0; TIMSK1 = 0; TIMSK2 = 0; TCCR0A = 0; TCCR0B = 0; TCCR1A = 0; TCCR1B = 0; TCCR2A = 0; TCCR2B = 0; PORTB |= DIGIT_MASK; DDRB |= DIGIT_MASK; PORTD = 0; DDRD = 0x7F; TCNT2 = 0; TIFR2 = (1U << TOV2); TIMSK2 = (1U << TOIE2); TCCR2B = (1U << CS22); sei(); while (1) { } }