|
下面贴个freescale的coldfire v1系列中mcf51cn128 MCU的一个示例,利用定时器实现输出捕获的功能。
MCF51CN128是freescale去年推出的V1 CORE的coldfire处理器,具有一个以太网控制器,是实现以太网应用的不错选择
具有50MHZ的主频
------------------------------------------------------------------------------------------------------------------------------
#include /* for EnableInterrupts macro */
#include "derivative.h" /* include peripheral declarations */
void InitSystems()
{
SOPT1 = 0x10; // Disable COP,RSTO
SPMSC1 = 0x00; // Disable LVD
SPMSC2 = 0x00; // Disable power-down modes
SPMSC3 = 0x00; // Disable LVWIE, low trip points
SCGC1 = 0xFF; // Enable bus clock to peripherals
SCGC2 = 0xFF; // Enable bus clock to peripherals
SCGC3 = 0xFF; // Enable bus clock to peripherals
SCGC4 = 0xFF; // Enable bus clock to peripherals
MCGTRM = NVMCGTRM; // Load Trim Values from flash into ICSTRM register
MCGSC_FTRIM = NVFTRIM_FTRIM; // Load Fine Trim Value from flash into FTRM register
} // end InitSystems
// Initialize the TPM1CH1 for Output Compare
void TPM1C1_Output_Compare() {
TPM1SC_CPWMS =0; // Edge aligned
TPM1C1SC_CH1IE = 1; // Enable channel 1 interrupt
TPM1C1SC_MS1x = 1; // Output compare
TPM1C1SC_ELS1x = 1; // toggle output on compare
TPM1C1V = 0x8000; // Interrupt after 32,768 decimal cycles.
// At 32.768Khz, 32,768 cycles yields interrupt every 1 second.
TPM1SC_PS = 7; // 4.194304Mhz/128 = 32.768Khz
TPM1SC_CLKSx = 1; // bus clock and start the timer
} //end TPM1C1_Output_Compare
/************************
Main Program Loop
************************/
void main(void) {
InitSystems();
TPM1C1_Output_Compare();
EnableInterrupts; /* enable interrupts */
for(;;) {
} /* loop forever */
/* please make sure that you never leave main */
}
/*********************************************************************
** Interrupt Service Routines
*********************************************************************/
interrupt VectorNumber_Vtpm1ch1 void TPM1CH1_ISR(void) {
TPM1C1SC_CH1F = 0; // Clear channel flag
TPM1C1V += 0x8000; // Increment compare value to next interrupt
}
|
|