中级会员
- 积分
- 432
- 威望
- 310
- 贡献
- 98
- 兑换币
- 76
- 注册时间
- 2008-3-23
- 在线时间
- 12 小时
|
<><FONT color=#2222dd size=3>以下是一个控制舵机的小程序,可舵机总是打到一边,硬件肯定没有问题,</FONT></P><P><FONT color=#2222dd size=3>我琢磨了数日都找不出原因,希望坛友帮帮忙,在下感激不尽!!!!</FONT></P><P><FONT color=#2222dd size=3></FONT> </P><P><FONT color=#2222dd size=3>#include <hidef.h> /* common defines and macros */<BR>#include <mc9s12dg128.h> /* derivative information */<BR>#pragma LINK_INFO DERIVATIVE "mc9s12dg128b"</FONT></P><P><FONT color=#2222dd size=3></FONT> </P><P><FONT color=#2222dd size=3>void main(void) {<BR>\<BR> <BR> CLKSEL=0x00; //时钟选择寄存器 关闭锁相环,选定外部时钟<BR> CLKSEL_PLLSEL = 0; <BR> PLLCTL_PLLON = 0; //锁相环电路禁止<BR> SYNR=2; <BR> REFDV=3; //BUS_CLK=2*16*(SYNR+1)/(REFDV+1)=24MHz;<BR> PLLCTL=192; //PLL控制寄存器 <BR> PLLCTL_PLLON = 1; //锁相环电路使能 bit6<BR> while(!CRGFLG_LOCK); //等待锁相环时钟达到预期值 bit3<BR> CLKSEL_PLLSEL = 1; //开启锁相环 */<BR> <BR> PWME = 0x00; /*01:50Hz 45:1kHz */ </FONT></P><P><FONT color=#2222dd size=3> PWMPOL = 0x22; </FONT></P><P><FONT color=#2222dd size=3> PWMCTL = 0x50; </FONT></P><P><FONT color=#2222dd size=3> PWMCLK = 0x02; </FONT></P><P><FONT color=#2222dd size=3> PWMSCLA = 4; <BR> <BR> PWMPER01 = 60000; /* Center 1500ms*3 */ </FONT></P><P><FONT color=#2222dd size=3> PWMDTY01 = 4500; /* 设置舵机角度 */ <BR> PWME = 0x22; /*01:50Hz 45:1kHz */ <BR> for(;;) {} /* wait forever */<BR> /* please make sure that you never leave this function */<BR></FONT></P> |
|