问题描述
我为我的 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 循环内的引脚一直在切换。我在这里遗漏了什么吗?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)