avr-c 16bit timer interrupt

avr-c 16bit timer interrupt
#define F_CPU 8000000L #include <avr/io.h> #include <avr/interrupt.h> //--------------------------------------------- unsigned char i; //--------------------------------------------- void segchar(unsigned char seg) { // dp|g|f|e|d|c|b|a switch (seg) { case 1: PORTD = ~0b00000110; // 1 break; case 2: PORTD = ~0b01011011; // 2 break; case 3: PORTD = ~0b01001111; // 3 break; case 4: PORTD = ~0b01100110; // 4 break; case 5: PORTD = ~0b01101101; // 5 break; case 6: PORTD = ~0b01111101; // 6 break; case 7: PORTD = ~0b00000111; // 7 break; case 8: PORTD = ~0b01111111; // 8 break; case 9: PORTD = ~0b01101111; // 9 break; default: PORTD = ~0b00111111; } } //--------------------------------------------- void timer_ini(void) { TCCR1B |= (1<<WGM12); // Clear Timer on Compare Match Register TIMSK |= (1<<OCIE1A); // start timer with compare interrupt OCR1A (H|L) // 8000000/256 = 31250 = 0111101000010010 OCR1AH = 0b01111010; // high OCR1AL = 0b00010010; // low TCCR1B |= (1<<CS12); // 256 prescaler } //--------------------------------------------- ISR(TIMER1_COMPA_vect) { if (i > 9) { i = 0; } segchar(i); i++; } //--------------------------------------------- int main(void) { timer_ini(); DDRD = 0xFF; DDRB = 0x00; PORTD = 0xFF; PORTB = 0x01; sei(); i = 0; while (1) { } }