本帖最后由 sn516952 于 2012-5-11 10:35 编辑
16F685的芯片.
void timer1_init(void)
{
T1CKPS1=0;
T1CKPS0=0;//00: 预分频1:1
TMR1IE = 1;//允许timer1溢出中断
TMR1H=0xF8; //赋值TMR1H
TMR1L=0x48; //赋值TMR1L 0xF848=1ms
TMR1CS = 0;//不与外部输入时钟同步
TMR1IF = 0;//溢出中断标志位.1=溢出.
//以下两行少了就不工作.
T0CS=0;//0= T0CS位清零选择定时器模式 内部指令周期时钟FOSC/4
T0IE=1;//1= 允许Timer0中断
TMR1ON =1;//使能timer1门控
TMR1IE=1;
GIE=1;//开总中断
}
偶然间发现
T0CS=0;//0= T0CS位清零选择定时器模式 内部指令周期时钟FOSC/4
T0IE=1;//1= 允许Timer0中断
timer1里面要加上这两句才工作. datasheet里也没有注明两个定时器有相关的地方.
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
if you do not turn on PEIE, TMR1IF will never trigger an interrupt (see the interrupt block diagram in the f!@#$king datasheet). thus, your ISR will never be serviced, unless other interrupt sources trigger the isr - this is where T0IF comes in.
if you do not turn on PEIE but T0IE (or any other interrupt sources) is turned on, the isr will be serviced. In the isr, TMR1IE and TMR1IF are tested, and TMR1 is reloaded, timer1_flag1 is incremented and a pin is flipped, as if PEIE is set.
All of that comes from reading and understanding the f#@$king datasheet.
一周热门 更多>