atmega16L 定时器溢出中断反常现象
定时器1中断子程序如下,测试过程中,发现,如果没有??????.......??????中间的两个FOR语句内容, 定时器就能正常工作。8uS .而如果加上这段内容,定时就不正常了。
我把这段去掉,直接该成简单的for语句,也不正常工作。这是为什么?请高手解答,谢谢
#pragma interrupt_handler timer1_ovf_isr:iv_TIMER1_OVF //8uS定时中断
void timer1_ovf_isr(void)
{
uchar i=0;
uchar j=0;
uchar k=0;
SREG = 0x00; //关闭中断
TCNT1=0xffbf; //>60 no 28us?
TCCR1B = 0x01; //无分频
PORTD ^= (1<<P35);
//
//?????????????????????????????????????????
for(i=0;i<8;i++)
{
if(Key_status==0x11)
{
if(Key_hit_time==0)
{
Key_status=0x22;
PORTD ^= (1<<TXDLED);
PORTB&=~(1<<i); //0
//PORTB |=(1<<PORTB0)
PORTA |=(1<<i); //
}
else
{
Key_lidu_reg--;
if(Key_lidu_reg==0)
{
if(Key_hit_status==0)
{
Key_hit_status=1;
Key_lidu_reg=Key_lidu_low;
}
else
{
Key_hit_status=0;
Key_lidu_reg=Key_lidu_high;
}
Key_hit_time--;
PORTB ^= (1<<i);
}
else
{
}
}
}
}
/////////
i=8;
j=0;
k=4;
for(i=8;i<12;i++)
{
if(Key_status==0x11)
{
if(Key_hit_time==0)
{
Key_status=0x22;
PORTC&=~(1<<j); //0
//PORTB |=(1<<PORTB0)
PORTC |=(1<<k);
}
else
{
Key_lidu_reg--;
if(Key_lidu_reg==0)
{
if(Key_hit_status==0)
{
Key_hit_status=1;
Key_lidu_reg=Key_lidu_low;
}
else
{
Key_hit_status=0;
Key_lidu_reg=Key_lidu_high;
}
Key_hit_time--;
PORTC ^= (1<<j);
}
else
{
}
}
}
j++;
k++;
}
//????????????????????????????????????????
SREG=0x80; //开启中断
} 是从那里学的这样写中断服务程序?
中断时间间隔为8us,你的中断服务程序语句这样多,执行一遍要多少个us?再加上for循环肯定要超过8us了,那么如何保证每8us出现中断?中断当然不正常了。
页:
[1]