Search code examples
embeddedmicrocontrollerinterruptatmegamicrochip

Static declaration of '__vector_1' follows non-static declaration


Im trying to create a program which will interrupt when I press the button. I have Atmega8 and I use Microchip studio for coding. I checked the document about interrupts on atmega's website however I can't say I totally got it.
Here is my code:

#define F_CPU 1000000UL
#define IRQ1 INT0_vect 
#define IRQ2 INT1_vect 

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

void init()
{
    DDRB=0b11111111;    
    PORTB=255;
    _delay_ms(2000);
    PORTB=0;
    DDRD = 0b00000000;
    GICR=0xc0;   
    MCUCR=0x08;
}

int main(void){
    
    init();
    volatile int mode = 0;
        
            ISR(IRQ1){
                _delay_ms(500);
                if (mode<3)mode++; else mode = 0;       
            }

            ISR(IRQ2){
                _delay_ms(150);
            }
}

Errors I get: Imgur

I would be glad if any admin edits my question and add picture here, website doesn't let me add photo because I need at least 10 reputation to post image


Solution

  • Don't try to define functions inside of other functions unless you really know what you are doing. You should move the ISR definitions to the top level of the file, putting them outside of main.