我为我的 ATmega32 编写了一个代码,以使用模拟比较器的中断点亮 LED,但 ISR 不会执行。我正在对 Proteus 进行测试。
#define F_CPU 8000000UL
#include <avr/io.h>
#include <avr/interrupt.h>
#define LED_DDR DDRA ///< DDR of indicator LED.
#define LED_PORT PORTA ///< Port of indicator LED.
#define LED_PIN PA0 ///< Pin of indicator LED.
void PORT_INIT(void);
void COMPARATOR_INIT(void);
/*!
* @brief ISR for Analog Comparator Interrupt; turn on LED if an interrupt occurs.
*/
ISR(ANA_COMP_vect){
LED_PORT |= (1<<LED_PIN);
}
int main(void){
PORT_INIT();
COMPARATOR_INIT();
sei(); ///< Enable global interrupts.
while(1);
}
/*!
* @brief Initialize ports.
*/
void PORT_INIT(void){
LED_DDR |= (1<<LED_PIN);
}
/*!
* @brief Initialize Analog Comparator.
*/
void COMPARATOR_INIT(void){
ACSR = 0x00; ///< Enable Analog Comparator by setting ACD to 0.
ACSR |= (ACIE)|(ACIS1); ///< Enable Analog Comparator Interrupt and set Interrupt Mode to Falling Output Edge.
}
我添加了一行代码来在 while 循环之间切换另一个引脚,以查看是否发生了任何中断,但 while 循环内的引脚一直在切换。我在这里错过了什么吗?