这里在程序中,通过使用定时器中断&来循环使用LED,如果有人按下开关,它应该停止第一个中断&触发第二个应该根据开关点亮LED按下。在这里,我有点困惑,哪个中断被调用。我提到了一些针对变化中断的书籍&写了几行设置PCMSK2。所得到的输出是“最初所有的LED都是循环的,当按下一个开关时......再次启动LED循环(这意味着程序正在读输入,而不是触发第二次中断),它不停止或者暂停&后面的led不亮。“任何人都可以帮忙吗?引脚电平变化中断 - 带内部中断的外部中断
#include <avr/io.h>
#include <avr/interrupt.h>
#define PINK_MASK \
((1<<PINK0)|(1<<PINK1)|(1<<PINK2)|(1<<PINK3)|(1<<PINK4)|(1<<PINK5)|(1<<PINK6)|(1<<PINK7))
volatile unsigned int intrs, i=1;
void enable_ports(void);
void delay(void);
extern void __vector_23 (void) __attribute__ ((interrupt));
extern void __vector_25 (void) __attribute__ ((signal));
void enable_ports()
{
DDRB = 0xff; //PORTB as output for leds
PORTB = 0xff;
DDRK = 0x00; //PORTK as input from switches
PORTK |= PINK_MASK;
PCMSK2 = PINK_MASK; //ENABLE PCMSK2, Setting interrupts
PCICR = 0x04;
PCIFR = 0x04;
TCCR0B = 0x03; //Setting TIMER
TIMSK0 = 0x01;
TCNT0 = 0x00;
intrs = 0;
}
void __vector_23 (void)
{
intrs++;
if(intrs > 60)
{
intrs = 0;
PORTB = (0xff<<i);
i++ ;
if(i == 10)
{
PORTB = 0xff;
i = 1 ;
}
}
}
void __vector_25 (void)
{
unsigned char switches;
switches = ((~PINK) & (PINK_MASK)); //Reading from switches
if(switches & (1<<PINK0))
PORTB = (PORTB<<PINK0);
else if (switches & (1<<PINK1))
PORTB = (PORTB<<PINK1);
else if (switches & (1<<PINK2))
PORTB = (PORTB<<PINK2);
else if (switches & (1<<PINK3))
PORTB = (PORTB<<PINK3);
else if (switches & (1<<PINK4))
PORTB = (PORTB<<PINK4);
else if (switches & (1<<PINK5))
PORTB = (PORTB<<PINK5);
else if (switches & (1<<PINK6))
PORTB = (PORTB<<PINK6);
else if (switches & (1<<PINK7))
PORTB = (PORTB<<PINK7);
}
int main(void)
{
enable_ports();
sei();
while(1)
{
}
}
感谢您的支持。
任何人都请帮忙! – sneezy 2010-11-10 00:11:04
对不起,我不使用AtmelμC。但是,也许你可以问http://embdev.net/ – AndreKR 2010-11-10 00:15:53
你的目标是什么特定设备? – evilspacepirate 2011-01-09 15:17:17