【发布时间】:2018-08-23 15:29:58
【问题描述】:
我试图将七段显示器与 Atmega16 芯片及其解码器 (74ls47) 连接,并使用 ISR 增加它显示的值。 ISR 应该打开和关闭一个 LED,然后增加 SSD 的值,但它只会使 LED 闪烁,SSD 没有任何反应。
#include <avr/io.h>
#include <avr/interrupt.h>
#include <util/delay.h>
#include "DIO.h"
unsigned int counter=0;
int main(void)
{
SREG |= (1<<7); //The Holy Gate
GICR |= (1<<7); //Enableing INT1
MCUCR |=(1<<2); //for INT1
MCUCR |=(1<<3); //for INT1
DDRC =0xFF;
PORTC =0;
DDRB |=(1<<0);
while (1)
{
}
}
ISR (INT1_vect)
{
digitalWrite('B', 0, 1);
_delay_ms(500);
digitalWrite('B', 0, 0);
if (counter <= 9) {
PORTC=counter;
counter++;
} else {
counter=0;
}
}
注意:digitalWrite 是一个在“DIO.h”文件中预定义的打开和关闭 LED 的函数
提前致谢。
【问题讨论】:
-
500ms 延迟不是中断的最佳选择。
-
确实,最好在每个中断中反转 LED 状态,然后您可以将其作为
digitalWrite('B', 0, LEDstate);传递一次 -
仍然,您说 LED 闪烁但 7 段显示器没有输出。这取决于您如何连接 7 段驱动器 74LS47。如果控制线
/LT和/RBI和/BI也连接到端口C,那么您应该将它们设置为1电平输出,如IC 数据表的真值表所示,否则将它们钳位同上。跨度> -
实际上,当我将 (PORTC=counter;) 替换为 (PORTC=any number) 行时,它可以完美运行
-
所以 Atmega16 的端口 确实 工作,但这只是一个随机结果:请关注我的最后一条评论。你试过
PORTC = counter | 0xF0;吗?
标签: c embedded avr isr atmega16