|
<>#include <hidef.h> /* common defines and macros */<BR>#include <mc9s12dg128.h> /* derivative information */<BR>#pragma LINK_INFO DERIVATIVE "mc9s12dg128b"</P><P>/*<BR>*********************************************************<BR>*pwm初始化函数 by demon 2007-5-12<BR>*********************************************************/<BR>void pwm_initial()//pwm初始化函数<BR>{ <BR>PWME=0x22;//通道01,45使能 <BR>PWMPOL=0x22;//通道01,45输出波形开始极性为1 <BR>PWMCTL=0x50;//通道01,45级联 <BR>PWMCLK=0x02;//通道01选择SA为时钟源 <BR>PWMSCLA=0X04;//通道01时钟SA为3MHz(24/(2*4))<BR>PWMPER01=60000;//设定通道01输出频率(50Hz)<BR>PWMPER45=12000;//设定通道45输出频率(2KHz)<BR>}</P><P><BR>/*<BR>*********************************************************<BR>*pwm输出函数 by demon 2007-5-12<BR>*程序描述;由输入参数向舵机和电机输出相应pwm<BR>*参数:舵机方向:3300-5700 速度:0-12000<BR>*********************************************************/<BR>void pwm(int speed,int direction)//pwm<BR>{<BR>pwm_initial();<BR>if(direction<3300) direction=3300; <BR>if(direction>5700) direction=5700; <BR>PWMDTY01=direction;<BR>if(speed>12000) speed=12000;<BR>PWMDTY45=speed; <BR>} </P><P> </P> |
|