智能车制作

标题: 难道不能用全局变量吗? 高手进来看看 [打印本页]

作者: kuaikuai    时间: 2008-4-25 04:30
标题: 难道不能用全局变量吗? 高手进来看看
<>程序如下:</P><P>#include &lt;hidef.h&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /* CPU底层配置 */<BR>#include &lt;mc9s12dg128.h&gt;&nbsp;&nbsp;&nbsp;&nbsp; /* 芯片相关信息 */<BR>#include &lt;math.h&gt;<BR>#pragma LINK_INFO DERIVATIVE "mc9s12dg128b"</P><P>&nbsp;</P><P>&nbsp;</P><P>/*全局变量的定义*/</P><P>unsigned int present_duty=760;&nbsp; <BR>&nbsp;</P><P>/**************************************************************************************<BR>函数名:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; PWM_INIT<BR>功能描述:&nbsp;&nbsp;&nbsp;&nbsp; PWM 初始化程序<BR>输入:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 无<BR>输出:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 无<BR>全局变量:&nbsp;&nbsp;&nbsp;&nbsp; PWMPRCLK,PWMSCLA,PWMSCLB,PWMCLK,PWMCTL,PWMCAE,PWMPOL,PWMPER0,PWMPER1,<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; PWMPER2,PWMPER3,PWMDTY0,PWMDTY1,PWMDTY2,PWMDTY3,PWME, present_duty,<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <BR>****************************************************************************************/&nbsp; <BR>void PWM_INIT(void)<BR>&nbsp;{&nbsp; //PWM 初识化<BR>&nbsp;&nbsp;&nbsp; PWMPRCLK=0x50;&nbsp; <BR>&nbsp;&nbsp;&nbsp; PWMSCLA=0x01;<BR>&nbsp;&nbsp;&nbsp; PWMSCLB=0x01;<BR>&nbsp;&nbsp;&nbsp; PWME=0xfc;&nbsp; <BR>&nbsp;&nbsp;&nbsp; PWMCLK=0xfc;<BR>&nbsp;&nbsp;&nbsp; PWMCTL=0xe0;<BR>&nbsp;&nbsp;&nbsp; PWMCAE=0x00;<BR>&nbsp;&nbsp;&nbsp; PWMPOL=0xfc;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; PWMPER67=7600;&nbsp; <BR>&nbsp;&nbsp; // PWMPER6=0x02;<BR>&nbsp;&nbsp; // PWMDTY6=0x00;<BR>&nbsp;&nbsp;&nbsp; PWMDTY67=present_duty;<BR>&nbsp;&nbsp; <BR>&nbsp;&nbsp; <BR>&nbsp;}<BR>&nbsp;<BR>/**************************************************************************************<BR>函数名:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; PORT_INIT<BR>功能描述:&nbsp;&nbsp;&nbsp;&nbsp; I/O 口初始化<BR>全局变量:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; DDRB<BR>调用模块:&nbsp;&nbsp;&nbsp;&nbsp; 无<BR>***************************************************************************************/<BR>void PORT_INIT(void)<BR>&nbsp;{&nbsp; <BR>&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; DDRB=0xFF;&nbsp; <BR>&nbsp;}<BR>&nbsp;</P><P>/**************************************************************************************<BR>函数名:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; main<BR>功能描述:&nbsp;&nbsp;&nbsp;&nbsp; 主程序<BR>全局变量:&nbsp;&nbsp;&nbsp;&nbsp; <BR>调用模块:&nbsp;&nbsp; &nbsp; PORT_INIT,PWM_INIT<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <BR>***************************************************************************************/<BR>void main(void) {<BR>&nbsp; int i=0,j=0;&nbsp; <BR>&nbsp; PORT_INIT();<BR>&nbsp; PWM_INIT();<BR>&nbsp; <BR>&nbsp;<BR>&nbsp; for(;;)<BR>&nbsp; {<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp; PORTB=0xf0;<BR>&nbsp; <FONT color=#f73809>present_duty=380;<BR></FONT>&nbsp;&nbsp; }&nbsp;&nbsp; <BR>&nbsp; </P><P>}</P><P>红色修改了值,程序运行后<FONT color=#f73809>present_duty 的值还是760&nbsp;&nbsp; 这是什么原因&nbsp; 难道不能用全局变量??&nbsp;</FONT></P>
作者: kuaikuai    时间: 2008-4-25 04:53
标题: Re:难道不能用全局变量吗? 高手进来看看
<>哦 低级错误 </P><P>已解决</P>
作者: superyongzhe    时间: 2008-4-25 23:13
标题: Re:难道不能用全局变量吗? 高手进来看看
的确是个低级错误!
作者: whut_wj    时间: 2008-4-29 18:40
标题: Re:难道不能用全局变量吗? 高手进来看看
<>...................</P><P>&nbsp;PWM_INIT();</P>
作者: wgggfiy    时间: 2009-4-25 20:56
请问是什么错误啊?看了这么久没看出来,汗




欢迎光临 智能车制作 (http://111.231.132.190/) Powered by Discuz! X3.2