milan.rajik
Banned
- Joined
- Apr 1, 2013
- Messages
- 2,524
- Helped
- 540
- Reputation
- 1,078
- Reaction score
- 524
- Trophy points
- 1,393
- Activity points
- 0
Why Timer1 Interrupt is not firing ? It has to fire every 160 ms.
Worked. ISR vector was wrong.
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 #define F_CPU 8000000UL #include <avr/io.h> #include <avr/interrupt.h> #include <util/delay.h> unsigned char mask[] = {0xFE, 0xFD, 0XFB, 0XF7, 0XEF, 0XDF, 0XBF}; //segments a , b, c, d, e, f, g unsigned char step = 0; //Timer1 Prescaler = 64; Preload = 20000; Actual Interrupt Time = 160 ms //Place/Copy this part in declaration section void InitTimer1() { SREG |= 0x80; OCR1AH = 0x4E; OCR1AL = 0x20; TCCR1A = 0x80; TCCR1B |= 0x0B; TIMSK |= 0xC0; } // TIMER1 overflow interrupt service routine // called whenever TCNT1 overflows ISR(TIMER1_OVF_vect) { PORTD = 0x60; PORTB = mask[step++]; //Assign mask values to turn on each segment of 1st SSD one by one PORTD = 0x20; if(step == 7)step = 0; //If last segment displayed was g then reset lookup table index to 0 so that segment a is displayed on next interrupt } int main(void) { DDRA = 0x00; PORTA = 0x00; DDRB = 0xFF; PORTB = 0xFF; DDRD = 0xFF; PORTD = 0x20; //Turn ON SSD1 connected to PD6 and turn OFF SSD2 connected to PD5 InitTimer1(); sei(); // enable global interrupts while(1) { } }
Worked. ISR vector was wrong.
Code C - [expand] 1 ISR(TIMER1_COMPA_vect)
Last edited: