#include "TIMER.h" #include "FU68xx_5_MCU.h" void Timer2_Init(void) { SetBit(PH_SEL , T2SEL); //P10 SetBit(PH_SEL , T2SSEL); //P07 ClrBit(TIM2_CR0 , T2PSC2); //计数器时钟分频选择 ClrBit(TIM2_CR0 , T2PSC1); //000-->24M 001-->12M 010-->6M 011-->3M ClrBit(TIM2_CR0 , T2PSC0); //100-->1.5M 101-->750K 110-->375K 111-->187.5K ClrBit(TIM2_CR0 , T2OCM); SetBit(TIM2_CR0 , T2IRE); //比较匹配中断/脉宽检测中断0-->Disable 1-->Enable ClrBit(TIM2_CR0 , T2CES); ClrBit(TIM2_CR1 , T2IPE); //输入Timer PWM周期检测中断使能 0-->Disable 1-->Enable ClrBit(TIM2_CR1 , T2IFE); //计数器上溢中断使能 0-->Disable 1-->Enable ClrBit(TIM2_CR1 , T2FE); //输入噪声滤波使能,小于4个时钟周期脉宽滤除 ClrBit(TIM2_CR1 , T2DIR); //QEP&ISD&步进模式专用:当前的方向 0-->正向 1-->反向 TIM2__DR = 1200; TIM2__ARR = 2400; ClrBit(TIM2_CR0 , T2MOD1); //00-->输入Timer模式 01-->输出模式 SetBit(TIM2_CR0 , T2MOD0); //10-->输入Counter模式 11-->QEP&ISD&步进模式 SetBit(TIM2_CR1 , T2CEN); //TIM2使能 0-->Disable 1-->Enable } void Timer3_Init(void) { SetBit(PH_SEL , T3SEL); //Timer3端口使能 ClrBit(PH_SEL1 , T3CT0); //默认端口为P11,功能转移后为P01,需TIMER4转移到P00 ClrBit(PH_SEL1 , T3CT1); //默认端口为P11,功能转移后为P01,需TIMER4转移到P00 ClrBit(TIM3_CR0 , T3PSC2); //计数器时钟分频选择 SetBit(TIM3_CR0 , T3PSC1); //000-->24M 001-->12M 010-->6M 011-->3M SetBit(TIM3_CR0 , T3PSC0); //100-->1.5M 101-->750K 110-->375K 111-->187.5K // SetReg(TIM3_CR0 , T3PSC2 | T3PSC1 | T3PSC0 , T3PSC2 | T3PSC1 | T3PSC0); SetBit(TIM3_CR0 , T3OCM); ClrBit(TIM3_CR0 , T3IRE); //比较匹配中断/脉宽检测中断0-->Disable 1-->Enable ClrBit(TIM3_CR0 , T3OPM); //0-->计数器不停止 1-->单次模式 ClrBit(TIM3_CR1 , T3IPE); //输入Timer PWM周期检测中断使能 0-->Disable 1-->Enable ClrBit(TIM3_CR1 , T3IFE); //计数器上溢中断使能 0-->Disable 1-->Enable ClrBit(TIM3_CR1 , T3NM1); //输入噪声脉宽选择 SetBit(TIM3_CR1 , T3NM0); //00-->不滤波 01-->4cycles 10-->8cycles 11-->16cycles SetBit(TIM3_CR0 , T3MOD); //0-->Timer模式 1-->输出模式 TIM3__CNTR = 0; TIM3__DR = 0; //分子,给定输出PWM占空比 TIM3__ARR = 1000; //分母周期值,给定输出PWM周期,频率1000 3k 2000 1.5k SetBit(TIM3_CR1 , T3EN); //TIM3使能 0-->Disable 1-->Enable } void Timer4_Init(void) { ClrBit(TIM4_CR1, T4EN); //0-停止计数;1-使能计数 SetBit(PH_SEL , T4SEL); //Timer4端口使能 SetBit(PH_SEL1 , T4CT0); //默认端口为P01,功能转移后为P00 SetBit(PH_SEL1 , T4CT1); //默认端口为P01,功能转移后为P00 SetBit(TIM4_CR0 , T4PSC2); //计数器时钟分频选择 SetBit(TIM4_CR0 , T4PSC1); //000-->24M 001-->12M 010-->6M 011-->3M ClrBit(TIM4_CR0 , T4PSC0); //100-->1.5M 101-->750K 110-->375K 111-->187.5K SetBit(TIM4_CR0 , T4OCM); ClrBit(TIM4_CR0 , T4IRE); //比较匹配中断/脉宽检测中断0-->Disable 1-->Enable ClrBit(TIM4_CR0 , T4OPM); //0-->计数器不停止 1-->单次模式 // ClrBit(TIM4_CR1, T4IR | T4IF | T4IP); // 清除中断标志位 ClrBit(TIM4_CR1 , T4IPE); //输入Timer PWM周期检测中断使能 0-->Disable 1-->Enable ClrBit(TIM4_CR1 , T4IFE); //计数器上溢中断使能 0-->Disable 1-->Enable ClrBit(TIM4_CR1 , T4NM1); //输入噪声脉宽选择 ClrBit(TIM4_CR1 , T4NM0); //00-->不滤波 01-->4cycles 10-->8cycles 11-->16cycles ClrBit(TIM4_CR0 , T4MOD); //0-->Timer模式 1-->输出模式 TIM4__CNTR = 0; TIM4__DR = 0; TIM4__ARR = 0; SetBit(TIM4_CR1 , T4EN); //TIM4使能 0-->Disable 1-->Enable }