#define F_CPU 8000000UL#include <avr/io.h>#include <avr/interrupt.h>#include <util/delay.h>unsignedchar mask[]={0xFE,0xFD,0XFB,0XF7,0XEF,0XDF,0XBF};//segments a , b, c, d, e, f, gunsignedchar step =0;//Timer1 Prescaler = 64; Preload = 20000; Actual Interrupt Time = 160 ms//Place/Copy this part in declaration sectionvoid 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 interruptswhile(1){}}
Looks like you are enabling OCIE1B interrupt without a related interrupt routine. First step would be to check that the main loop is actually continuously executing.
I don't have much experience with AVR. I mainly use PIC. I generated the InitTimer1() code using mikroe Timer Calculator. This is the code it generated. It was using Timer1_COMPA_vect. If I use COMPB_vect then ISR doesn't fire.
This is for ATtiny2313A. I need to interrupt every 160 ms. I need to turn ON segments a, b, c, d, e, f, g of Units Digit SSD on every interrupt. I am attaching Proteus 8.1 file and Atmel Studio files. The segment d will be always ON. I don't know why.
Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
//Timer1 Prescaler = 64; Preload = 20000; Actual Interrupt Time = 160 ms//Place/Copy this part in declaration sectionvoid InitTimer1(){
SREG_I_bit =1;
OCR1AH =0x4E;
OCR1AL =0x20;
TCCR1A =0x80;
TCCR1B |=0x0B;
OCIE1A_bit =1;}void Timer1Overflow_ISR() org IVT_ADDR_TIMER1_COMPA {//Enter your code here }