我的程序是使用Timer 1的1通道为输出比较,0通道为输入捕捉。我现在并没有接通0通道,所以不存在输入捕捉的事情。
我在调试的时候,却不能进入输出比较中断,请问为什么?(主函数已经开中断,并且不使能COP)
急盼大家指教。
部分函数如下:
主函数:
void main(void)
{ EnableInterrupt;
Init_Timer();
for(;;)
{;}
}
初始化Timer定时器,使用TIM1CH1为输出比较,设定初值为OutCampareValue = 7813 void Init_Timer(void) { unsigned char a; a = T1SC; T1SC = 0x26; //set TSTOP and TRST simultaneously,let the counter stop at 0x00; T1SC1 = 0x54; T1SC0 = 0x48; T1MOD = 65535; T1SC_TSTOP = 0; T1CH1 = T1CNT + OutCampareValue; } 中断服务程序 void interrupt INT_TIM1CH1OuputCompare(void) { unsigned char a;//be used to read the T1SC1 unsigned char i;//be used to mark the number of transmited bytes __asm sei; //关中断 T1CH1 = T1CNT + OutCampareValue;//reload the T1CH1 HPulse = PulseNum /100; Speed = (unsigned char)(HPulse * MeterPerHPulse * 2 *3.6); // km/h Mileage = Mileage + HPulse * MeterPerHPulse / 1000; PulseNum = 0; T_data[0] = 0; //load the data to be transmited T_data[1] = Speed; T_data[2] = (unsigned char)(Mileage / 65536 / 256); T_data[3] = (unsigned char)(Mileage / 65536 % 256); T_data[4] = (unsigned char)(Mileage % 65536 / 256); T_data[5] = (unsigned char)(Mileage % 65536 % 256); T_data[6] = (T_data[0] + T_data[1] + T_data[2] + T_data[3] + T_data[4] + T_data[5]); for( i = 0;i<7;i++) { SCI_Transmit(T_data); } a = T1SC1; T1SC1_CH1F = 0; // Clear CH1F interrupt flag (the 7th bit) //TransmitId = TRUE; wuguang++; __asm cli; //开中断 }
在prm文件中,定义中断入口地址。 //VECTOR 3 INT_TIM1CH0InputCapture VECTOR 4 INT_TIM1CH1OuputCompare //VECTOR 15 KBI_Int
|