这是时钟的初始化:
//Initialize internal clock:5.4MHz bus frequency
ICGTRM = 0x80;//周期调整
ICGC1 = 0x28;
ICGC2 = 0x31;
while(ICGS1_LOCK == 0); //0时当前没有锁 1时锁定 ,等待锁定
定时器一的初始化:
void InitTPM1(void)
{
TPM1SC = 0x4e;
TPM1MODH = 0x03;
TPM1MODL = 0x64; //86.786KHz / 868 = 100Hz
}
interrupt void _TPM1Interrupt(void)
{
unsigned char TPM1Buffer;
TPM1Buffer = TPM1SC;
TPM1SC_TOF = 0; //clear TOP Flag
TPM10mSInterrupt = 1;
}
定时器2的初始化:
void InitTPM2(void)
{
TPM2SC = 0x4d;//总线时钟
TPM2MODH = 0x00; //
TPM2MODL = 0x11; //125KHz / 25 = 5KHz(100uS) 模值
}
interrupt void _TPM2Interrupt(void)
{
unsigned char TPM2Buffer,i,j;
TPM2Buffer = TPM2SC; //read TOM1SC
TPM2SC_TOF = 0; //clear TOP Flag
i=j=0;
//读红外输入口
//……
}
若开启定时器2中断,用仿真器运行,定时器1就挂掉,不起作用;
若删掉InitTPM2()语句,关闭定时器2,定时器1正常,程序正常运行,求各路大侠们解答??? |