【发布时间】:2015-11-05 19:03:02
【问题描述】:
我的 Atmega328p 出现中断问题。我使用的是 Arduino Nano 16 Mhz 5V,所以应该不是硬件问题。 这是我的代码:
#include <avr/io.h>
#include <avr/interrupt.h>
volatile uint16_t counter;
int main(void)
{
DDRB |= (1<<PB5);
TCCR1B |= (1 << CS10); // set prescaler to 1
TIMSK1 |= (1 << TOIE1); // set overflow interrupt
sei(); // enable interrupts
while (1)
{
// Main loop
}
}
ISR (TIMER1_OVF_vect)
{
counter++;
if (counter > 200)
{
counter = 0;
PORTB ^= _BV(PB5);
}
}
我想尽可能频繁地中断,但是在这种配置下,二极管每 1 秒闪烁一次 - 这太慢了,如果可能的话,我至少需要每 10us 或更短的时间。它可以是任何其他定时器,我不在乎。
【问题讨论】:
标签: arduino microcontroller avr