#include <hidef.h> /* for EnableInterrupts macro */#include "derivative.h" /* include peripheral declarations */void MCU_init(void);unsigned char flag;interrupt 26 void MTIM_ISR(void) {MTIMSC_TOF = 0;}interrupt 11 void Timovr(void){ TPM1SC_TOF=0;}interrupt 6 void TPM1CH1(void){ TPM1C1SC_CH1F=0; PTBD_PTBD1 = 0; // Make pin output low once Compare happened.}interrupt 5 void TPM1CH0(void){ // ISR for TPM1 channel 0TPM1SC_CLKSA =0; // Stop TPM1 Counter incrementing(void)TPM1C0SC;TPM1C0SC_CH0F=0;TPM1CNT = 0x0000;TPM1SC_CLKSA = 1; // Start TPM1 Counter incrementingTPM1C1V = 100; // Put value in compare register.PTBD_PTBD1 = 1; // Make pin output high once Capture happened.PTBD_PTBD2 = ~PTBD_PTBD2; // Check capture is happened.flag = 1;}void main(void) {MCU_init();TPM1SC_CLKSA = 1; flag = 0; EnableInterrupts; /* enable interrupts */ /* include your code here */ for(;;) { while(flag == 0) ; flag = 0; } /* loop forever */ /* please make sure that you never leave main */}void MCU_init(void) {/******************** LVI**************************/SPMSC1 = 0b00110100; //0x34=> Enable LVISPMSC2 = 0x00;//0b00100000;//0x20 =>LVDV = 1;LVWV = 0; LVD Trip Point = 4.0vSOPT1 = 0x04; // COP Disabled,STOP mode Disabled,SDA on PTB6, SCL on PTB7.SOPT2 = 0x00; //TPM1CH1 on PTB5.TPM1CH0 on PTA0./******************** PORT A ********************/PTAD = 0x00; // Port A Data register (PTAD_PTAD _PTAD.MergedBits.grpPTAD)PTADD = 0x02; // 0b00000010 =>Port A Data Direction register ,I/P= PTA1/PTA2/PTA3,O/P = PTA0PTAPE = 0x00; // Internal pull-up register disabled/******************** PORT B ********************/PTBD = 0x54; // Port B Data registerPTBDD = 0xD6; //0b11010110 => Port B Data Direction register, I/P= PTA1/PTA2/PTA3,O/P = PTA0PTBPE = 0x00; // Port B Data Direction register ,I/P= PTB0/PTB3/PTB5,O/P = PTB1/PTB2/PTB4/PTB6/PTB7PTBD_PTBD6 = 1; //Discharge the Ign coil./************* Analog Comparator ***************************/ACMPSC = 0x00;//Analog Comparator Disabled/************* Analog To Digital Conversion ***************************/ ADCCFG = 0xD8; //Clock Divide by 4,MODE=>10-bit conversion,Input Clock=>Bus clock. ADCSC2 = 0x00; ADCSC1 = 0x1F;//ADC Module disabled,Interrupt disable APCTL1 = 0x9c; // Analog I/p => PTA2,PTA3,PTB0,PTB3/*************** Internal Clock Source Select *************************/ICSSC = *(unsigned char*)0xFFAE; ICSTRM = *(unsigned char*)0xFFAF;ICSC1 = 0x04; //Output of FLL is selected.ICSC2 = 0x00;while(!ICSSC_IREFST) { /* Wait until the source of reference clock is internal clock */ }/****I2C ***********/// IICC1 = 0x00; /**************** Modulo Timer *********************************************************///Reset clears TOIE. Do not set TOIE if TOF = 1. Clear TOF first, then set TOIE.MTIMSC = 0x70; //MTIM Status and Control Register//MTIM Overflow Interrupt Enable,MTIM counter is reset to $00,MTIM counter is stopped,MTIMCLK = 0x08; //MTIM Clock Configuration Register //Bus Clock Source Select,Clock Source Prescaler=> ÷ 256 //1 tik count = 16 usec,So MTIM will overflow after 4.096 msecMTIMMOD = 0x00; //MTIM Modulo Register/*************** Timer/PWM Module **********************************************************/TPM1SC = 0x46; //TPM counter disable,TPM/64 = 16MHz/64 = 250 KHz,So 1 Count = 4 usec. TPM2SC = 0x46; //TPM counter disable,TPM/64 = 16MHz/64 = 250 KHz,So 1 Count = 4 usec. TPM2MOD = 0x18;// TPM2 will overflow every 100 usec overflow.TPM1C0SC = 0x48;//Channel 0 for capture on falling edge.TPM1C1SC = 0x50;}