智能车制作

标题: 请大侠帮忙!好多人都没能解释,看你的了 [打印本页]

作者: yangyang    时间: 2008-4-29 06:43
标题: 请大侠帮忙!好多人都没能解释,看你的了
<>捕捉下降沿的问题:<BR>#include &lt;hidef.h&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /* common defines and macros */<BR>#include &lt;mc9s12dg128.h&gt;&nbsp;&nbsp;&nbsp;&nbsp; /* derivative information */<BR>#pragma LINK_INFO DERIVATIVE "mc9s12dg128b"<BR>void SciInit()<BR>{<BR>&nbsp; SCI0BDL=52;// (unsigned char)((16000000UL /* OSC freq */ / 2) / 9600 /* baud rate */ / 16 /*factor*/<BR>&nbsp; SCI0CR1=0;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/*normal,no parity*/<BR>&nbsp; SCI0CR2=0X0C;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /*RIE=1,TE=1,RE=1*/<BR>}<BR>/*-------发射端程序----------------------*/<BR>void SciTx(unsigned char text)<BR>{<BR>&nbsp; while (!(SCI0SR1&amp;0x80));&nbsp; /* wait for output buffer empty */<BR>&nbsp; SCI0DRH=0;<BR>&nbsp; SCI0DRL=text;<BR>}<BR>unsigned char PulseCnt;<BR>void main(void)<BR>{<BR>&nbsp; <BR>&nbsp; SciInit();<BR>&nbsp; DDRB=0XFF;<BR>&nbsp; PORTB=0XFF;<BR>&nbsp; asm sei;<BR>&nbsp; TIOS=0X00;<BR>&nbsp; TSCR1=0X80;<BR>&nbsp; TSCR2=0X01;<BR>&nbsp; TCTL4=0X02;<BR>&nbsp; TIE=0X01;<BR>&nbsp; TFLG1=0X01;<BR>&nbsp; //DLYCT=0X03;<BR>&nbsp; PulseCnt=0X00;<BR>&nbsp; <BR>&nbsp; asm cli;<BR>&nbsp;// EnableInterrupts;<BR>&nbsp; for(;;){} //等待中断<BR>}<BR>#pragma CODE_SEG_NEAR_SEG NON_BANKED<BR>&nbsp;<BR>&nbsp;void interrupt IC0_ISR(void) <BR>&nbsp; {<BR>&nbsp;&nbsp; PulseCnt++;<BR>&nbsp;&nbsp; SciTx(PulseCnt);<BR>&nbsp;&nbsp; TFLG1=0X01;<BR>&nbsp;&nbsp; PORTB=~PulseCnt;<BR>&nbsp; }<BR>#pragma CODE_SEG DEFAULT</P><P>这个程序运行到&nbsp;&nbsp; "&nbsp; &nbsp;for(;;){} //等待中断&nbsp;&nbsp;&nbsp;"&nbsp;&nbsp;&nbsp;&nbsp; 就跳出,程序能捕捉到下降沿,但是为什么能跳出来,我就搞不清楚了,问了好多人都没能解释,看高手的了!</P>
作者: demon    时间: 2008-4-29 07:57
标题: Re:请大侠帮忙!好多人都没能解释,看你的了
<>&nbsp;把中断改成这样实验下:</P><P>void interrupt IC0_ISR(void) <BR>&nbsp; {DisableInterrupts;</P><P>TC0=0;<BR>&nbsp;&nbsp; PulseCnt++;<BR>&nbsp;&nbsp; SciTx(PulseCnt);<BR>&nbsp;&nbsp; TFLG1=0X01;<BR>&nbsp;&nbsp; PORTB=~PulseCnt;<BR>&nbsp;EnableInterrupts;</P><P>}</P>
作者: auto    时间: 2008-4-29 18:21
标题: Re:请大侠帮忙!好多人都没能解释,看你的了
是程序初使化的问题,
作者: yangyang    时间: 2008-4-29 19:35
标题: Re:Re:请大侠帮忙!好多人都没能解释,看你的了
谢谢各位的指教,我先试验下,看看成不!
作者: yangyang    时间: 2008-4-29 23:49
标题: Re:Re:请大侠帮忙!好多人都没能解释,看你的了
我试验过了,还是不成,还是跳出for{}循环,初始化也没什么问题啊,搞不懂了就!
作者: superyongzhe    时间: 2008-4-30 00:25
标题: Re:请大侠帮忙!好多人都没能解释,看你的了
你怎么知道它跳出for(;;){} //等待中断&nbsp;了????
作者: 920lyj    时间: 2008-5-2 01:12
标题: Re:请大侠帮忙!好多人都没能解释,看你的了
你是不是单步运行的,单步就会这样,一直运行那个中断程序,还是你的中断向量对了吗?可能是其它问题
作者: yangyang    时间: 2008-5-3 00:31
标题: Re:请大侠帮忙!好多人都没能解释,看你的了
谢谢大家的指教,本人已经把程序搞通了!o(∩_∩)o...多谢提醒




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