【发布时间】:2019-11-20 07:43:31
【问题描述】:
我正在尝试为 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)
{
}
}
【问题讨论】:
-
如果你想在上升沿获得 ISR,你应该将 PINCTRL 设置为 0x2 afaik。时钟输入是什么意思,PB0作为简单的GPIO?我认为您应该手动清除 ISR 标志。
-
对不起,我只是将它标记为“时钟”,因为我正在做一个简单的同步数据传输。我会研究清除 ISR 位。
标签: interrupt avr atmelstudio isr