1

我开始使用 Uno,我能够从我在网上找到的旋转库中获得一个中断工作,但是当我将项目移动到 Mega 并尝试将它更改为它停止的不同引脚时。我花了几个小时试图从在线资源中找出兆的中断引脚,但找不到任何好的资源来充分解释兆中断引脚。

我正在尝试使用这样的中断。

  Rotary r = Rotary(10,11);
void setup(){
  PCICR |= (1 << PCIE0);
  PCMSK0 |= (1 << PCINT4) | (1 << PCINT5);
  sei();
  }

ISR(PCINT0_vect){
//stuff
}

如果有人有首选方法,我使用什么引脚进行中断并不重要。我只需要它工作。

4

1 回答 1

0

此处描述了 Arduino 中断。它比您提供的示例代码更易于使用。

//Mega2560
// external interrupt int.0    int.1    int.2   int.3   int.4   int.5            
// pin                  2         3      21      20      19      18



void setup()
{
  // interrupt # 0, pin 2
  attachInterrupt(0, myISR, CHANGE); // Also LOW, RISING, FALLING
}

void loop()
{

}

void myISR() // must return void and take no arguments
{
  // stuff
}

您不需要启用中断sei();,因为attachInterrupt()它为您服务。但是您可以使用禁用中断cli();并使用重新启用它们sei();

于 2014-11-08T05:08:26.870 回答