未生成Attiny204中断标志

时间:2019-07-10 16:13:57

标签: interrupt avr atmelstudio isr

我正在尝试为Attiny204写一个(相当)基本的软件,它可以在时钟输入被拉高时处理中断。

当我在Atmel Studio的调试模拟器中运行代码并将时钟输入设置为高电平时,不会生成中断标志。当我手动产生中断标志时,中断确实会触发。

我尝试使用不同的引脚,甚至其他端口。我似乎无法让模拟器产生中断标志。

过去,我在模拟器中使用过AtMega328P并使用了等效代码,并且效果很好。

ISR(PORTA_PORT_vect)
{
  //In this function we must:
  //1. Shift all data up
  shiftUp();

  //2. Get new 8th bit
  bit8 = VPORTA.IN & (1 << 1);

  //3. Set Data Output Pin to bit0
  if(bit0 == 0)
    VPORTA.OUT &= ~(1 << 3);
  else
    VPORTA.OUT |= (1 << 3);

  //4. Calculate new dimValue and dimMilliseconds
  calcDim();
  calcDelay();
}

int main(void)
{
  initVariables();
  /*
    Below this, we must set the Data Direction (DD) of each pin we assigned.
  */

  //Below, set the ISC of the Zero Cross Pin and the Clock Pin to allow interrupts
  PORTA_PIN0CTRL |= 0b00000001; //Zero Cross
  //PORTA_PIN1CTRL = 0b00000000; //Data In
  //PORTA_PIN2CTRL = 0b00000000; //Data Next
  //PORTA_PIN3CTRL = 0b00000000; //Triac Control

  PORTB_PIN0CTRL |= 0b00000001; //Clock

  //VPORTB.INTFLAGS |= 0b00000001;

  //Set Port direction.
  VPORTA.DIR = 0x30;
  VPORTB.DIR = 0x00;

  /*
    Below this, we must enable interrupts.
  */
  sei();
  /* Replace with your application code */
  while (1) 
  {

  }
}

1 个答案:

答案 0 :(得分:0)

您为什么要写VPORTAVPORTB? Tiny204没有此寄存器。 您在端口A的引脚0的两个边缘都启用了中断(PIN0CTRL的位0被设置为BOTHEDGES),并且没有清除端口A的ISR中的中断标志。请看一下数据表:

The interrupt request remains active until the interrupt flag is cleared. See the peripheral's INTFLAGSregister for details on how to clear interrupt flags.