' __ vector_1&#x27的静态声明遵循非静态声明

发布于 2025-01-25 17:46:56 字数 904 浏览 4 评论 0原文

我试图创建一个程序,当我按按钮时会中断。我有Atmega8,我使用Microchip Studio进行编码。 我检查了有关Atmega网站上中断的文档,但我不能说我完全明白了。
这是我的代码:

#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);
            }
}

错误,我会得到: imgur

如果有人编辑我的问题并在此处添加图片,我会很高兴让我添加照片,因为我至少需要10个声誉才能发布图像

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

抱猫软卧 2025-02-01 17:46:56

除非您真的知道自己在做什么,否则不要尝试定义其他功能内部的功能。您应该将ISR定义移至文件的最高级别,并将其放在main之外。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文