void init_timer(void) { TSCR1_TEN =0;
TSCR2 =0x07; TIOS |=0x04;
OC7M |=0x04;
TIE |=0x04;
}
void timer_channel2 (int TIMER2) { TC2 =TIMER2; //设定时间隔 TSCR1|=0x80; //TSCR1_TEN=1 }
#pragma CODE_SEG NON_BANKED interrupt void timer_channel2_isr(void) { TIE &=0xFB; //Timer Interrupt Mask disable (通道2) TFLG1 |=0x04; //清中断标志位
}
void main(void)
{ int a; TIMER2=20; init_timer();
timer_channel2 (TIMER2); EnableInterrupts;
a=TCNT; /* put your own code here */ for(;;) {} /* wait forever */ }
定时一直有问题。在软仿真的时候从TCNT中读出的值一直不对,有时候连中断都进不了。
调了好长时间了就是找不到原因,如果哪位大哥有个相似的例程请给小弟参考一下,还请
各位大哥多多关照!
|