智能车制作

标题: 求助 S12 ECT 输出比较,定时不准,求指点 [打印本页]

作者: chuxingzhe    时间: 2017-11-6 20:43
标题: 求助 S12 ECT 输出比较,定时不准,求指点
#include <hidef.h>      /* common defines and macros */
#include "derivative.h"      /* derivative-specific definitions */
#define LEDCPU PORTB_BIT0
#define LEDCPU_dir DDRB_BIT0
#define uint unsigned int
#define uchar unsigned char
uint time;

void init_ect()
{      
  TSCR1_TFFCA=1; //定时器标志位快速清除
  TSCR1_TEN=1;  //定时器使能
  TIOS=0xff;    //所有通道输出比较
  TCTL1=0x00;    //后四个通道设置位定时器与输出引脚断开
  TCTL2=0x00;    //前四个通道设置为定时器与输出引脚断开
  TIE=0x00;       //禁止所有通道定时中断
  TSCR2=0x00;    //预分频系数0f,时钟周期为  
  TFLG1=0xff;    //清除各IC/OC中断标志位
  TFLG2=0xff;     //清除自由定时器中断标志位
}

void main(void)
{
  /* put your own code here */
  DisableInterrupts;
  init_ect();
  LEDCPU=0;
  LEDCPU_dir=1;   
        EnableInterrupts;
  for(;;) {
    TFLG1_C0F = 1;              //清除标志位
    TC0 =40000;         //设置输出比较时间为5ms
    while(TFLG1_C0F == 0);      //等待,直到发生输出比较事件
     time++;
     if(time==200)
     {
      time=0;
      LEDCPU=~LEDCPU;
     }
    _FEED_COP(); /* feeds the dog */
  } /* loop forever */
  /* please make sure that you never leave main */
}

  为什么 定时不准,不是1S呢,求大神指导,谢谢。




欢迎光临 智能车制作 (http://www.znczz.com/) Powered by Discuz! X3.2