初次用PIC18F66K80,发现一个奇怪的问题。用Timer1定时器定时1ms程序,发现无论怎样修改TMR1H和TMR1L的值,定时中断均为5.4us。所用晶振为16M,4倍频。去掉4倍频,则定时中断为21.6us。初始化和中断程序如下:
void Capture_Init()
{
T1CON = 0X02; //指令时钟,预分频比为1:1
TMR1H = (65536-16000)/256; //1MS定时
TMR1L = (65536-16000)%256;
PMD1bits.TMR1MD = 0;
T1CONbits.TMR1ON = 1; //启动计时
PIE1bits.TMR1IE = 1;
PIR1bits.TMR1IF = 0;
}
void interrupt ISR(void)
{
static char i;
if(PIR1bits.TMR1IF == 1)
{
PIR1bits.TMR1IF == 0;
TMR1H = (65536-16000)/256;
TMR1L = (65536-16000)%256;
i++;
if(i%2)
bLED_FLAP = 0; //点亮LED
else
bLED_FLAP = 1; //关闭LED
}
}
跪求高手解决。 |