RSTSRC = 0x00 /* Disable missing clock detector */ //否则的话会在换时钟的时候导致单片机机复位 PCA0MD &= ~0x40; 禁止看门狗 EA = 0; //禁止全局中断 /*时钟切换*/ /* SmartRTC 32768Hz */ // leave VDD Monitor enabled. CLKSEL &= ~0x70; // Specify a clock divide value of 1 while(!(CLKSEL & 0x80)); // Wait for CLKRDY to ensure the // divide by 1 has been applied CLKSEL = 0x03; // Select smaRTClock oscillator // as the system clock RSTSRC = 0x06; // Enable missing clock detector and /* 再次初始化定时器0 */ if(SystemSclk_24M){ TH0 = TIMER0_RELOAD_HIGH_24M; // Init Timer0 High register TL0 = TIMER0_RELOAD_LOW_24M; // Init Timer0 Low register TMOD &= 0xf0; TMOD |= 0x01; // Timer0 in 16-bit mode ET0 = 1; // Timer0 interrupt enabled //TCON = 0x10; // Timer0 ON TR0 = 1; }else{ TH0 = TIMER0_RELOAD_HIGH_32K; // Init Timer0 High register TL0 = TIMER0_RELOAD_LOW_32K; // Init Timer0 Low register CKCON &= ~0x03; // T1M = 0; SCA1:0 = 01 // 特别注意这个..在串口改变这个..在这里切换时要注意设置.否则定时不是预想的时间. TMOD &= 0xf0; TMOD |= 0x02; // Timer0 in 16-bit mode ET0 = 1; // Timer0 interrupt enabled //TCON = 0x10; // Timer0 ON TR0 = 1; } EA = 1;//开全局中断 过程就这样..