【发布时间】:2016-11-07 09:15:24
【问题描述】:
谁能弄清楚为什么我的外部中断 0 不起作用?我正在使用带有 ATmega164P 的 AVR STK 500 板。是不是因为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;
}
}
【问题讨论】:
-
board_init() 是做什么的?您是否设置/启用外部中断?
-
不要在 ISR 中
delay。 -
只是为了强调 JimmyB 的声明,不要将延迟放在 ISR 中。
标签: c initialization interrupt avr atmega