AVR-C turning led off after number of blinks with interrupts

arduinoavrblinkinterruptsled

so what I am trying to do is that I am trying to make the led blink for a certain number of times before it turns off. I want to avoid using delays so I tried
utilizing the interrupt and I also used a placeholder value like x to count the number of times it goes through interrupt, so one it reaches that value it will turn off, however I am having trouble getting it to work, any ideas

            /*
             * GccApplication3.c
             *
             * Created: 2015-04-01 6:13:58 AM
             *  Author: Bangladesh
             */ 


            #include <avr/io.h>   
            #include <util/delay.h> 
            #include <avr/interrupt.h> 
            #define stp_led PB0 
            #define dir_led PB1
            #define led_port PORTB
            #define led_ddr DDRB
            #define F_CPU 16000000UL 
            int x = 0;


            int main(void)
            { 
                ///////////////////////////////////////////////////////
                led_ddr |= (1 << stp_led); //enable led as an output pin  
                led_ddr |= (1 << dir_led);   
                //led_port |= (1<<stp_led);   
                led_port |= (1<<dir_led); 
                ///////////////////////////////////////////////////////
                TCCR1B |= (1 << WGM12);  // configuring timer 1 for ctc mode
                OCR1A = 15625;
                TIMSK1 |= (1 << OCIE1A); // enable ctc interrupt

                TCCR1B |= ((1 << CS12) | (1<< CS10)); //Start at 1024 prescaler 

                sei(); //Enable global interrupts

                 //Sets ctc compare value to 1hz at 1mhz AVR clock, with prescaler of 64




             while(1)  
                {  

                } 
            } //end of while loop 


            ISR(TIMER1_COMPA_vect)
            {   

                function_details (10, 1);

            }

            void function_details (stp,dir){  

                if (dir == 1){ 
                    led_port |= (1 << dir_led); 
                } 
                else if (dir == 0){ 
                    led_port &= ~ (1 << dir_led);
                }    
            while (1){
                led_port ^= (1 << stp_led);
                if (x == stp){ 
                    led_port &= ~ (1 << stp_led);  
                    return 0;
                    }  
                    x++; 
                }

            }

Best Answer

Try something like this

     ISR(TIMER1_COMPA_vect)
     {   
           if(led_blink_count < 10)
           {
                //Toggle the led state
                led_blink_count++;
           }             
     }

Have the timer trigger at the frequency you want the led to blink at. Set led_blink_count to 0 to restart the blinking.