简体   繁体   English

外部中断0不起作用

[英]External Interrupt 0 doesn't work

Can anybody figure out why my external interrupt 0 doesn't work? 有人能弄清楚为什么我的外部中断0不起作用吗? I am using an AVR STK 500 board with an ATmega164P on it. 我正在使用带有ATmega164P的AVR STK 500板。 Is it because the pin D2 has got two functions? 是因为D2针具有两种功能吗?

#include <asf.h>
#include <avr/interrupt.h>
#include <avr/io.h>

#define F_CPU 8000000UL
#include <util/delay.h>

ISR(INT0_vect)
{
    PORTB = 1;
    for(int i = 0; i < 7; i++)
    {
        _delay_ms(500);
        PORTB << 1;
    }
}

int main (void)
{
    board_init();

    sei();

    PORTD = 0xFF;
    DDRD = 0x00;
    PORTB = 0x00;
    DDRB = 0xFF;

    while(1)
    {
        PORTB = PIND;
    }
}

I guess you don't enable the external interrupt. 我猜你没有启用外部中断。

Look at the data sheet section 10.2. 查看数据手册第10.2节。

10.2.2 EIMSK – External Interrupt Mask Register 10.2.2 EIMSK –外部中断屏蔽寄存器

When an INT2:0 bit is written to one and the I-bit in the Status Register (SREG) is set (one), the corresponding external pin interrupt is enabled. 当将INT2:0位写入1并且将状态寄存器(SREG)中的I位设置为1时,将启用相应的外部引脚中断。 The Interrupt Sense Control bits in the External Interrupt Control Register, EICRA, defines whether the external interrupt is activated on rising or falling edge or level sensed. 外部中断控制寄存器EICRA中的中断检测控制位定义了在检测到上升沿或下降沿或电平时激活外部中断。

So you have to set 所以你必须设置

EIMSK |= (1 << INT0);

to enable INT0 and potentially EICRA to define what signal edge you want to react at. 使INT0和潜在的EICRA能够定义您希望在哪个信号边沿反应。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM