本帖最后由 jack5288 于 2018-8-14 17:10 编辑
新唐N76E003定时器例程Timer01_M0 计算为63uS实测86uS 求助!
时间=(65535-0XFC0F)/16M(晶振频率)=1009/16=63uS.
而实测为86uS,开始我以为是晶振频率不对,但实测为16M。
请大家帮忙分析下!!!
例程如下:
#define TH0_INIT 0xFC //5.0ms@XTAL=12MHz, Period = (10.85/2) ms@XTAL=22.1184MHz
#define TL0_INIT 0x0F
#define TH1_INIT 0xE0 //2.5ms@XTAL=12MHz, Period = (5.425/2) ms@XTAL=22.1184MHz
#define TL1_INIT 0x00
/************************************************************************************************************
* TIMER 0 interrupt subroutine
************************************************************************************************************/
void Timer0_ISR (void) interrupt 1 //interrupt address is 0x000B
{
TH0 = TH0_INIT;
TL0 = TL0_INIT;
P12 = ~P12; // GPIO toggle when interrupt
}
/************************************************************************************************************
* TIMER 1 interrupt subroutine
************************************************************************************************************/
void Timer1_ISR (void) interrupt 3 //interrupt address is 0x001B
{
TH1 = TH1_INIT;
TL1 = TL1_INIT;
P03 = ~P03; // GPIO toggle when interrupt
}
/************************************************************************************************************
* Main function
************************************************************************************************************/
void main (void)
{
TMOD = 0XFF;
Set_All_GPIO_Quasi_Mode;
TIMER0_MODE0_ENABLE; //Timer 0 and Timer 1 mode configuration
TIMER1_MODE0_ENABLE;
clr_T0M;
clr_T1M;
TH0 = TH0_INIT;
TL0 = TL0_INIT;
TH1 = TH1_INIT;
TL1 = TL1_INIT;
// set_ET0; //enable Timer0 interrupt
set_ET1; //enable Timer1 interrupt
set_EA; //enable interrupts
set_TR0; //Timer0 run
// set_TR1; //Timer1 run
while(1)
{
TH0 = TH0_INIT;
TL0 = TL0_INIT;
set_TR0;
while(!TF0);
clr_TR0;
P12 = ~P12;
TF0 = 0 ;
}
}
|