·É˼¿¨¶û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. **

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