在avr器件中,只有两个IO端口中断矢量INT0和INT1。
我有三个开关应该会产生三个中断。我使用INT0为第一个交换机编写了一个中断代码。现在,我可以使用INT1编写第二个中断,这将耗尽我的向量。下面是我为INT0 ISR编写的代码:
ISR (PORTD_INT0_vect){
PORTD.INTFLAGS = 0x01; // clear INT0IF flag.
PORTD_OUT = PORTD_OUT | (1<<4); // led on.
}我可以重新定义这个ISR以启用第二个交换机的中断吗?
我在主要功能中设置的寄存器如下:
PORTD.INT0MASK = 0x04; // PD2 is the source of interrupt for INT0.
PORTD.INTCTRL = 0x03; // Disable INT1, enable INT0 and place it a high-priority level.
PORTD.PIN2CTRL = 0x03; // configure PD2 pin to interrupt on the low level of signal.
PMIC.CTRL = 0x07;    // enable high,medium, and low level interrupts.
sei();         // enable interrupt globally.发布于 2015-10-07 09:42:46
外部干扰的想法是,你要知道发生了什么事情,而不是发生了什么。在您的ISR中,您必须读出开关连接到的输入的状态,并根据读出来确定要做什么。若要检测状态是否更改,请保留端口输入状态的副本,并使用新读取的值执行XOR (对整个端口执行此操作,而不仅仅是针对单个引脚)。
发布于 2015-10-07 09:46:02
我不是XMEGA的专家,但我可以建议使用PD1作为中断引脚:
PORTD.INT0MASK = 0x04; // PD2 is the source of interrupt for INT0.
PORTD.INT1MASK = 0x02; // PD1 is the source of interrupt for INT1.
PORTD.INTCTRL = 0x0F; // Enable INT1, enable INT0 and place them a high-priority level.
PORTD.PIN2CTRL = 0x03; // configure PD2 pin to interrupt on the low level of signal.PORTD.PIN1CTRL = 0x03; // configure PD1 pin to interrupt on the low level of signal.发布于 2016-08-06 11:40:57
每个端口有两个中断。如果需要多于2的中断,可以使用更多的端口。您可以将第三个交换机连接到第二个端口,并在那里使用INT0。
https://stackoverflow.com/questions/32988537
复制相似问题