好像不能上传,我把函数贴出来:
#include /* common defines and macros */
#include /* derivative information */
#pragma LINK_INFO DERIVATIVE "mc9s12dg128b"
#pragma CODE_SEG NON_BANKED
unsigned int start_time,end_time;
union {
//unsigned char st[2];
int ticks;
} pulse0;
union {
//unsigned char st[2];
int ticks;
} pulse1;
union {
//unsigned char st[2];
int ticks;
} pulse2;
union {
//unsigned char st[2];
int ticks;
} pulse3;
interrupt void isr0(void) {
end_time=TC0;//捕捉寄存器的值作为结束时间;
start_time=TC0H;//保持寄存器的值作为开始时间;
if(end_time>=start_time){
pulse0.ticks=(int)(1000000/(end_time-start_time));
}else{
pulse0.ticks=(int)(1000000/(1*0x10000+end_time-start_time));
}
TFLG1=0x01;//清除中断标志;
}
interrupt void isr1(void) {
end_time=TC1;//捕捉寄存器的值作为结束时间;
start_time=TC1H;//保持寄存器的值作为开始时间;
if(end_time>=start_time){
pulse1.ticks=(int)(1000000/(end_time-start_time));
}else{
pulse1.ticks=(int)(1000000/(1*0x10000+end_time-start_time));
}
TFLG1=0x02;//清除中断标志;
}
interrupt void isr2(void) {
end_time=TC2;//捕捉寄存器的值作为结束时间;
start_time=TC2H;//保持寄存器的值作为开始时间;
if(end_time>=start_time){
pulse2.ticks=(int)(1000000/(end_time-start_time));
}else{
pulse2.ticks=(int)(1000000/(1*0x10000+end_time-start_time));
}
TFLG1=0x04;//清除中断标志;
}
interrupt void isr3(void) {
end_time=TC3;//捕捉寄存器的值作为结束时间;
start_time=TC3H;//保持寄存器的值作为开始时间;
if(end_time>=start_time){
pulse3.ticks=(int)(1000000/(end_time-start_time));
}else{
pulse3.ticks=(int)(1000000/(1*0x10000+end_time-start_time));
}
TFLG1=0x08;//清除中断标志;
}
void ini_wheel(void) {
TIOS=0x00;//定义引脚为输入捕捉功能
TSCR1=0x80;//启用计时器;等待模式无效;Debug模式下不停止;手动对输入捕捉读取寄存器相应标志位清零;
TCTL4=0x55;//0~3通道上升沿捕捉;
TIE=0x0f;// 允许0~3通道输入捕捉中断;
TSCR2=0x02;//禁止计时器溢出中断;禁止重置功能;计时器自由运行预分频系数为4,主计时器为2MHz;
DLYCT=0x01;//256个总线周期,即0.000032s之后输入有效(去噪声);
ICOVW=0xff;//捕捉寄存器和保持寄存器只有为空时才能被写入;
ICSYS=0x0e;//队列模式;只有当TC0被读出时才中断。
}
void main(void){
ini_wheel();
EnableInterrupts;
for(;;){}
}
////===========================================================================
// No more.
//===========================================================================
|