智能车制作

 找回密码
 注册

扫一扫,访问微社区

查看: 10364|回复: 0
打印 上一主题 下一主题

求助 S12 ECT 输出比较,定时不准,求指点

[复制链接]

1

主题

11

帖子

0

精华

注册会员

Rank: 2

积分
79
威望
39
贡献
32
兑换币
22
注册时间
2017-11-4
在线时间
4 小时
跳转到指定楼层
1#
发表于 2017-11-6 20:43:43 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
#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呢,求大神指导,谢谢。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

关于我们|联系我们|小黑屋|亿加合和智能车制作 ( 黑ICP备2022002344号

GMT+8, 2024-5-7 03:43 , Processed in 0.069272 second(s), 26 queries , Gzip On.

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表