1
\$\begingroup\$

I am trying to learn how to use interrupts for a project using an Attiny85. I have written a simple program from what I have learned from tutorials. However when I try to build the program in Atmel Studio, I get this error message:

"Error 2 static declaration of '__vector_1' follows non-static declaration"

I do not understand what this means or where my mistake located. I've searched all around for answers but I haven't found the reason for the error yet. Here is my code:

#include <avr/io.h>
#include <util/delay.h>
#include <avr/interrupt.h>
#include <avr/sleep.h>


int main (void)
{

    DDRB = 0b11111011; // set all pins to be output except PB2 to prevent false signals 

    GIMSK |= (1<<INT0); //set PB2 to interrupt
    sei();

    MCUCR |=(1<<ISC00);  //set to detect any change as interrupt
    MCUCR &= ~(1<<ISC01);


    ISR(INT0_vect)

    {

    // dot
    PORTB = 0b00001000;
    _delay_ms(500);
    PORTB = 0b00000000;
    _delay_ms(200);

    // dot
    PORTB = 0b00001000;
    _delay_ms(500);
    PORTB = 0b00000000;
    _delay_ms(200);

    // dot
    PORTB = 0b00001000;
    _delay_ms(500);
    PORTB = 0b00000000;
    _delay_ms(600);

    // dash
    PORTB = 0b00001000;
    _delay_ms(1000);
    PORTB = 0b00000000;
    _delay_ms(500);

    // dash
    PORTB = 0b00001000;
    _delay_ms(1000);
    PORTB = 0b00000000;
    _delay_ms(500);

    // dash
    PORTB = 0b00001000;
    _delay_ms(1000);
    PORTB = 0b00000000;
    _delay_ms(600);

    // dot
    PORTB = 0b00001000;
    _delay_ms(500);
    PORTB = 0b00000000;
    _delay_ms(200);

    // dot
    PORTB = 0b00001000;
    _delay_ms(500);
    PORTB = 0b00000000;
    _delay_ms(200);

    // dot
    PORTB = 0b00001000;
    _delay_ms(500);
    PORTB = 0b00000000;
    _delay_ms(2000);


        }

    while (1) {


    }



    }

If anyone could provide assistance it would be much appreciated.

Thank you,

-David

\$\endgroup\$
3
\$\begingroup\$

You've written your ISR within main(). Don't do that; close the previous function first.

void main(void)
{
   ...
}

ISR(...)
{
   ...
}
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.