我在使用定时器2的过程中出现定时时间不准的问题,本来想1s(近似1s)闪烁LED灯一次,可现在基本上几十个ms就闪烁一次。不知大家有没有用过的,帮我看下错在那里了??
void C8051F9x_SynInit(void)
{
PCA0MD &= ~0x40;
FLSCL = 0x40; // FLSCL.bypass=1
OSCICN = 0x8F; // enable internal osc
CLKSEL = 0x00; // 24.5MHz as System clock
XBR2 = 0x40; // Crossbar Enable
}
void C8051F9x_Timer2Init(void)
{
CKCON &= ~0x60; // Timer2 uses the clock defined by the T2XCLK bit in TMR2CN
TMR2CN &= ~0x01;
TMR2RL = 0x15a0; // TMR2RL = 65536 - 30ms/1/(24.5Mhz/12) 定时30ms,12分频近似为2Mhz
TMR2 = TMR2RL;
TMR2CN = 0x04;
ET2 = 1;
EA = 1;
}
void Timer2ISR(void) interrupt 5
{
cnt++;
if(cnt>=33)
{
TF2H = 0;
cnt = 0;
PININV(LED2);
}
}
main()
{
C8051F9x_SynInit();
C8051F9x_Timer2Init();
while(1);
}
|