飞思卡尔智能车的舵机测试程序
#include <hidef.h> /* common defines and macros */
#include <MC9S12XS128.h> /* derivative information */
#pragma LINK_INFO DERIVATIVE "mc9s12xs128"
void SetBusCLK_16M(void)
{
CLKSEL=0X00;
PLLCTL_PLLON=1; //锁相环电路允许位
SYNR=0x00 | 0x01; //SYNR=1
REFDV=0x80 | 0x01;
POSTDIV=0x00;
_asm(nop);
_asm(nop);
while(!(CRGFLG_LOCK==1));
CLKSEL_PLLSEL =1;
}
void PWM_01(void) { //舵机初始化
PWMCTL_CON01=1; //0和1联合成16位PWM;
PWMCAE_CAE1=0; //选择输出模式为左对齐输出模式
PWMCNT01 = 0; //计数器清零;
PWMPOL_PPOL1=1; //先输出高电平,计数到DTY时,反转电平
PWMPRCLK = 0X40; //clockA 不分频,clockA=busclock=16MHz;CLK B 16分频:1Mhz
PWMSCLA = 0x08; //对clock SA 16分频,pwm clock=clockA/16=1MHz;
PWMCLK_PCLK1 = 1; //选择clock SA做时钟源
PWMPER01 = 20000; //周期20ms; 50Hz;
PWMDTY01 = 1500; //高电平时间为1.5ms;
PWME_PWME1 = 1;