[求助]自动重装的 timer2 .自动重载可以省掉中断保护处理与恢复定时器的时间,可以弥补中断保护处理时间不定(特别是C语言),带来的定时器周期的偏差。
我的程序不通,下面有问题吗??
////4mhz,mega16.avricc.用定时器2(10ms得到一次溢出中断_其实是匹配中断)
void timer2_init(void){
TCCR2=0x00; //stop
ASSR =0x00; //不使用async mode
TCNT2=0x00; //setup
OCR2 =155; //比较值=155
TCCR2=0x0e; //ctc256分频,不输出 1110:4/256/155=100hz
}
void mcu_init(void){
//...
timer2_init();
//...
MCUCR = 0x00;
GICR = 0x00;
TIMSK = 0x80;
SEI();
}
#pragma interrupt_handler timer2_comp_isr:4
void timer2_comp_isr(void){
timer_en; //标志
data_led=0x00;outled_data;
}