帮我写一个SKEAZ1284单片机用FTM测方波频率和占空比的PTD1端口输入初始化程序
#include <SKEAZ1284.h>
void FTM_Init() { // Enable clock for FTM0 SIM_SCGC |= SIM_SCGC_FTM0_MASK;
// Set FTM0 clock source to system clock
SIM_CLKDIV1 &= ~SIM_CLKDIV1_OUTDIV4_MASK;
// Disable write protection for FTM0 registers
FTM0_MODE |= FTM_MODE_WPDIS_MASK;
// Enable FTM0 module
FTM0_MODE |= FTM_MODE_FTMEN_MASK;
// Set FTM0 mode to input capture
FTM0_MODE |= FTM_MODE_CAPTEST_MASK;
// Enable FTM0 channel 0 as input capture
FTM0_C0SC |= FTM_CnSC_ELSA_MASK;
// Configure PTD1 as input for FTM0 channel 0
PORTD_PCR1 = PORT_PCR_MUX(4);
// Configure FTM0 channel 0 to capture on rising edge
FTM0_C0SC |= FTM_CnSC_ELSB_MASK;
// Clear any pending interrupts on FTM0 channel 0
NVIC_ICPR |= (1 << (INT_FTM0 - 16));
// Enable interrupts for FTM0 channel 0
NVIC_ISER |= (1 << (INT_FTM0 - 16));
}
int main() { FTM_Init();
while (1)
{
// Your main code here
}
return 0;
原文地址: https://www.cveoy.top/t/topic/hUOs 著作权归作者所有。请勿转载和采集!