通过PLL锁相环在外部晶振为16MHz时得到24MHz, 现为了证实是否是24MHz,设置了主定时器(4分频),这时定时器在10922.66us后就应溢出(公式为(4/24)*65536=10922.66us),但我在PB0口接了示波器观看,发现为7ms左右,望各位高手指正,到底什么地方错了
#include /* common defines and macros */
#include /* derivative information */
#pragma LINK_INFO DERIVATIVE "mc9s12dg128b"
//初始化外围设备接口
void PeriphInit(void)
{
unsigned char clear;
DisableInterrupts; //关全局中断
// PB[7..0] 作为输出,初始为高电平
PORTB = 0xFF;
DDRB = 0xFF;
//初始化主定时器
TSCR1 = 0x80; /* enable timer TCNT */
TSCR2 = 0x82; /* TCNT prescaler setup 4分频*/
//设置PLL锁相环(内部)时钟24MHz为系统时钟 (外部时钟为16MHz,经PLL内部时钟为24MHz)
CLKSEL &= 0x7F;
REFDV = 1;
SYNR = 2;
while(!(CRGFLG&0x08));
CLKSEL |= 0x80;
EnableInterrupts; //开全局中断
}
//主定时器中断
#pragma CODE_SEG NON_BANKED
void interrupt Int_TimerOverFlow(void)
{
unsigned char i;
TFLG2_TOF = 1; //clear timer overflow flag
PORTB_BIT0=!PORTB_BIT0;
}
#pragma CODE_SEG DEFAULT
void main(void)
{
/* put your own code here */
PeriphInit();
for (;;) ;
}
|