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

Roh
4,6807 gold badges51 silver badges86 bronze badges
asked Jul 22, 2015 at 3:32
\$\endgroup\$

1 Answer 1

3
\$\begingroup\$

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

void main(void)
{
 ...
}
ISR(...)
{
 ...
}
answered Jul 22, 2015 at 3:39
\$\endgroup\$
0

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.