中级会员
- 积分
- 387
- 威望
- 271
- 贡献
- 86
- 兑换币
- 64
- 注册时间
- 2008-6-28
- 在线时间
- 15 小时
|
<> #include <hidef.h> /* common defines and macros */ <BR> #include <mc9s12dg128.h> /* derivative information */<BR> #pragma LINK_INFO DERIVATIVE "mc9s12dg1</P><P>unsigned int count_all=0,purse_1=0,purse_2=0,purse_3=0,purse_4=0,speed,lx=0; <FONT color=#f70938>定义了全局变量,但都被分配到了同一个地址,就是最开始的000000处,</FONT> <FONT color=#ff0033>一运行就有值:255 <BR></FONT> <BR> void Init_INT_RTI(void); </P><P> void Init_INT_Timer(void); </P><P> ... <BR> <BR> <BR> void main(void) <BR> { <BR> <BR> Init(); <BR> <BR> .... <BR> EnableInterrupts; <FONT color=#ff0066>在此处开启中断</FONT><BR> for(;;) <BR> {<BR> signal = PORTB; <BR> v=calculate();<FONT color=#ff0033>在这里调用了calculate函数,</FONT> </P><P> ...<BR> }<BR> }<BR> ....<BR> void Init_INT_RTI(void) <BR> { <BR> RTICTL = 0x74; <BR> <BR> CRGINT_RTIE=1; <BR> } <BR> #pragma CODE_SEG NON_BANKED<BR> <BR> void interrupt timer(void) <BR> { <BR> CRGFLG_RTIF=1; </P><P> count_all = PACN32 ;<BR> <BR> PACN32=0; <BR> lx = (int)(0.22*count_all);<BR> <BR> <BR> } </P><P> void Init_INT_Timer(void) <BR> { <BR> TCTL4 = 0X03;<BR> PACTL_PAEN=1; //PBEN=1,事件技术模式,上升沿触发,PACLK 允许中断<BR> ICPAR = 0X0F;<BR> PACN32=0;</P><P> } <BR> <BR> <BR> <BR><BR> <BR> <BR> int calculate(void)<BR> { .....<BR> return pid()*50; <FONT color=#ff0033>开启中断后运行到此处程序就停止了,把Enableinterrupt语句去掉好了</FONT><BR> } <BR> <BR> <BR> int pid(void) <BR> { <BR> ....</P><P> return((int)(P+I=D)); <BR> }<BR> <BR><FONT color=#ff0066>我去掉main里的一条语句,程序又会在另一处停止,</FONT> </P><P>谢谢大家帮忙解答 <BR> <BR></P> |
|