void init_pwm1(void) //选PWM1作为舵机的工作信号 工作频率为200HZ
{
PWME &=0XFC; // 关PWM1
PWMPRCLK =0x00; // BUS /1
PWMCLK |=0X02; // 选CLOCKA
PWMSCLA =0X3C; // CLOCKA=BUS /(2 *60)=200000
PWMPOL |=0X03; // PWMchannel 1 output is high at the beginning of the period,
PWMCAE &=0XFC; // 左对齐
PWMCTL |=0x10; // 选PWM1为16位
PWMPER0 =0x03;
PWMPER1 =0xE8; // 设定周期为1000 再结合上面就可得到200HZ的脉冲
// 200000 /1000 =200
PWMDTY0 =0;
PWMDTY1 =75; // 开始的占空比为7.5% 默认车不转向
}
PWME &=0xFC; //先关
PWMDTY1=100; //占空比为10%
PWME |=0x03; //后开
|