// LED-display Clock #define F_CPU 8000000 #define F_TIMER 600 #define PERIOD ((F_CPU/F_TIMER)-1) #include #include #include #include volatile uint8_t tf; // timer flag for 1 second volatile uint8_t digit[6]; const int8_t code7seg[10] = {20, 215, 76, 69, 135, 37, 36, 87, 4, 5}; // 7 segment code uint8_t hr=20, min=0, sec=0; //set start time void inc_time(void) { sec++; if (sec==60) { sec=0; min++; if (min==60) { min=0; hr++; if (hr==24) hr=0; } } } // distribute number to digits void number_output(int h, int m, int s) { digit[0]= h/10; digit[1]= h%10; digit[2] = m/10; digit[3] = m%10; digit[4] = s/10; digit[5] = s%10; } // timer interrupt ISR(TIMER1_COMPA_vect) { static uint8_t active_digit=0, select=1; static int cnt; // multilex display PORTC = 0b00111111; // all digits off active_digit++; select <<= 1; if (active_digit == 6 ) { active_digit = 0; select = 1; } PORTD = code7seg[digit[active_digit]]; PORTC = ~select; // Low = current digit on cnt++; if (cnt == F_TIMER) { cnt = 0; tf = 1; // 1 second flag } } int main(void) { // init ports DDRD = 0b11111111; DDRC = 0b00111111; // initialize timer1 // mode 4, CTC // prescaler 1 TCCR1A = 0; TCCR1B = (1<