void opmGpioInit(void)
{
PC_DDR_DDR1 = 1; //输出管脚
PC_CR1_C11 = 1;
PC_CR2_C21 = 1;
PC_DDR_DDR2 = 0; //输入管脚
PC_CR1_C12 = 1;
PC_CR2_C22 = 0;
}
void opmInit(void)
{
TIM1_PSCRH = 0x00;
TIM1_PSCRL = 0x00; //时钟分频寄存器 计数器的时钟频率(fCK_CNT)=fCK_PSC/(PSCR[15:0]+1)
//与CCR的差值决定脉冲的宽度
TIM1_ARRH = (uint8_t)(5000 >> 8) ; //设置PWM的周期为5000us
TIM1_ARRL = (uint8_t)(5000&0xFF);
//控制延时时间
TIM1_CCR1H = (uint8_t)(1000 >> 8); //通道1配置占空比
TIM1_CCR1L = (uint8_t)(1000);
//配置通道1为输出模式
TIM1_CCMR1_OC1M = 7; //PWM模式1
TIM1_CCMR1_OC1PE = 1 ; //使能预装载
TIM1_CCER1_CC1P = 0 ; //配置输出极性为高电平
TIM1_CCER1_CC1E = 1 ; //使能PWM的输出
//捕获设置
TIM1_CCER1_CC2E = 0; //使能通道捕获
TIM1_CCMR2_CC2S = 0x01 ; //配置通道2为输入模式
TIM1_CCER1_CC2P =0 ; //采样高电
TIM1_CCER1_CC2E = 1; //使能通道捕获
TIM1_SMCR_TS = 6; //配置触发选择
TIM1_SMCR_SMS = 6;//配置在重新捕获到触发信号后产生更新事件
TIM1_CR1_DIR = 0; //向上计数
TIM1_CR1_CMS = 0 ; //计数模式为边沿对其起码
TIM1_CR1_OPM = 1; //使能OPM
TIM1_CR1_ARPE = 0; //禁止自动重装
TIM1_CR1_CEN = 1 ; //使能定时器1
TIM1_BKR_MOE = 1; // Enable the main output.
TIM1_EGR_UG = 1 ; // 允许在产生更新事件时重装定时器值
}
void eOpmModeInit(void)
{
opmGpioInit();
opmInit();
}
|