飞思卡尔S12单片机ECT模块使用实例 下载本文

/** ################################################################### ** Filename : Project_2.c ** Project : Project_2

** Processor : MC9S12XEP100CAG ** Version : Driver 01.14

** Compiler : CodeWarrior HCS12X C Compiler ** Date/Time : 2014-5-21, 8:55 ** Abstract :

** Main module.

** This module contains user's application code. ** Settings : ** Contents :

** No public methods **

** ###################################################################*/ /* MODULE Project_2 */

/* Including needed modules to compile this module/procedure */ #include \#include \#include \#include \

/* Include shared modules, which are used for whole project */ #include \#include \#include \#include \

/* User includes (#include below this line is not maintained by Processor Expert) */ /************************************************************/ /* 初始化ECT模块 */ /************************************************************/ void initialize_ect(void){

//ECT_TSCR1_TFFCA = 1; // 定时器标志位快速清除

ECT_TSCR1_TEN = 1; // 定时器使能位. 1=允许定时器正常工作; 0=使主定时器不起作用(包括计数器)

ECT_TIOS = 0x03; //指定所有通道为输出比较方式

ECT_TCTL2_OM0 = 0; // 后四个通道设置为定时器与输出引脚断开 ECT_TCTL2_OL0 = 1; // 前四个通道设置为定时器与输出引脚断开

ECT_TCTL2_OM1 = 0; // 后四个通道设置为定时器与输出引脚断开 ECT_TCTL2_OL1 = 1; // 前四个通道设置为定时器与输出引脚断开 //ECT_DLYCT = 0x00; // 延迟控制功能禁止

// ECT_ICOVW = 0x00; // 对应的寄存器允许被覆盖; NOVWx = 1, 对应的寄存器不允许覆盖

// ECT_ICSYS = 0x00; // 禁止IC及PAC的保持寄存器 ECT_TIE = 0x00; // 禁止所有通道定时中断

ECT_TSCR2 = 0x04; // 预分频系数pr2-pr0:111,,时钟周期为4us,

ECT_TFLG1 = 0xff; // 清除各IC/OC中断标志位 //定时器中断标志1 ECT_TFLG2 = 0xff; // 清除自由定时器中断标志位 */ // ECT_TC0 = 60000 ; //ECT_TC1 = 10 ; } int x,y;

void main(void) {

/* Write your local variable definition here */

/*** Processor Expert internal initialization. DON'T REMOVE THIS CODE!!! ***/ PE_low_level_init();

/*** End of Processor Expert internal initialization. ***/ initialize_ect();

/* Write your code here */ x=0;y=0; for(;;) {

ECT_TFLG1_C0F = 1; //清除标志位

ECT_TC0 = ECT_TCNT + 32767; //设置输出比较时间为0.125s while(ECT_TFLG1_C0F == 0); //等待,直到发生输出比较事件 // ECT_TFLG1_C0F = 1; //清除标志位

// ECT_TC0 = ECT_TCNT + 31250; //设置输出比较时间为0.125s // while(ECT_TFLG1_C0F == 0); //等待,直到发生输出比较事件 }

/*** Processor Expert end of main routine. DON'T MODIFY THIS CODE!!! ***/ for(;;){}

/*** Processor Expert end of main routine. DON'T WRITE CODE BELOW!!! ***/ } /*** End of main routine. DO NOT MODIFY THIS TEXT!!! ***/

/* END Project_2 */ /*

** ################################################################### **

** This file was created by Processor Expert 3.02 [04.44] ** for the Freescale HCS12X series of microcontrollers. **

** ################################################################### */