智能车制作
标题:
关于定时和测速的问题
[打印本页]
作者:
zhw
时间:
2008-4-20 19:32
标题:
关于定时和测速的问题
<
>#include <hidef.h> /* common defines and macros */<BR>#include <mc9s12dg128.h> /* derivative information */<BR>#include "start12.h"<BR>#pragma LINK_INFO DERIVATIVE "mc9s12dg128b"</P><P>static speed;<BR>void get_speed()<BR> { <BR>while (TFLG2==0x80) <BR> TSCR1=0x00;<BR> speed =PACN0;<BR> }<BR>void Init_INT_Timer(void)<BR> { <BR>TSCR2 =0x85; /* 128Hz at 16M bus clok */ /* 128Hz * 2/3 at 24m bus clock */ /* in fact it is a little more than it. */ <BR>TIOS =0x00; /* I/O select */ <BR>TCTL4 =0x03;<BR>TSCR1=0x80; /* TSCR1_TEN=1 //Timer Enable */ <BR>ICPAR = 0x01;<BR>DDRB=0xff; <BR>PORTB=0xff;<BR>TCNT=0x0002;<BR>TFLG2=0x00;<BR>} <BR>void main()<BR>{ for(;;){<BR> Init_INT_Timer();<BR> get_speed() ;<BR> if ( speed ==0 ) {<BR> PORTB = 0x7e ;<BR> delay (1000);<BR> } <BR> if ( speed >0 && speed <10) {<BR> PORTB = 0xbd ;<BR> delay (1000); <BR> }<BR> if(speed>9) { <BR> PORTB = 0xdb;<BR> delay (1000); <BR> }<BR> }<BR> }<BR>每次运行后 B 口都没反应 用 hiwave 查定时计数器中数值有变化 请问我们的问题出在什么地方</P><P class=MsoNormal style="MARGIN: 0pt"><SPAN lang=EN-US><FONT size=3>#include <hidef.h><SPAN style="mso-spacerun: yes"> </SPAN>/* common defines and macros */</FONT></SPAN></P><P class=MsoNormal style="MARGIN: 0pt"><SPAN lang=EN-US><FONT size=3>#include <mc9s12dg128.h><SPAN style="mso-spacerun: yes"> </SPAN>/* derivative information */</FONT></SPAN></P><P class=MsoNormal style="MARGIN: 0pt"><SPAN lang=EN-US><FONT size=3>#pragma LINK_INFO DERIVATIVE "mc9s12dg128b"</FONT></SPAN></P><P class=MsoNormal style="MARGIN: 0pt"><SPAN lang=EN-US><?xml:namespace prefix = o ns = "urn:schemas-microsoft-com
ffice:office" /><o:p><FONT size=3> </FONT></o:p></SPAN></P><P class=MsoNormal style="MARGIN: 0pt"><SPAN lang=EN-US><FONT size=3><SPAN style="mso-spacerun: yes"> </SPAN><SPAN style="mso-spacerun: yes"> </SPAN></FONT></SPAN></P><P class=MsoNormal style="MARGIN: 0pt"><SPAN lang=EN-US><FONT size=3>void main(void) </FONT></SPAN></P><P class=MsoNormal style="MARGIN: 0pt"><SPAN lang=EN-US><FONT size=3>{<SPAN style="mso-spacerun: yes"> </SPAN></FONT></SPAN></P><P class=MsoNormal style="MARGIN: 0pt; TEXT-INDENT: 10.5pt; mso-char-indent-count: 1.0"><SPAN lang=EN-US><FONT size=3>DDRB=0xff; </FONT></SPAN></P><P class=MsoNormal style="MARGIN: 0pt"><SPAN lang=EN-US><FONT size=3><SPAN style="mso-spacerun: yes"> </SPAN>PORTB=0xff; </FONT></SPAN></P><P class=MsoNormal style="MARGIN: 0pt"><SPAN lang=EN-US><FONT size=3><SPAN style="mso-spacerun: yes"> </SPAN>TSCR2=0x05; </FONT></SPAN></P><P class=MsoNormal style="MARGIN: 0pt"><SPAN lang=EN-US><FONT size=3><SPAN style="mso-spacerun: yes"> </SPAN>TSCR1=0x80; </FONT></SPAN></P><P class=MsoNormal style="MARGIN: 0pt"><SPAN lang=EN-US><FONT size=3><SPAN style="mso-spacerun: yes"> </SPAN>DDRB=0xff; </FONT></SPAN></P><P class=MsoNormal style="MARGIN: 0pt"><SPAN lang=EN-US><FONT size=3><SPAN style="mso-spacerun: yes"> </SPAN>PORTB=0xff;</FONT></SPAN></P><P class=MsoNormal style="MARGIN: 0pt"><SPAN lang=EN-US><FONT size=3><SPAN style="mso-spacerun: yes"> </SPAN>TCNT=0x0002;</FONT></SPAN></P><P class=MsoNormal style="MARGIN: 0pt"><SPAN lang=EN-US><FONT size=3><SPAN style="mso-spacerun: yes"> </SPAN>if (TFLG2==0x80 )</FONT></SPAN></P><P class=MsoNormal style="MARGIN: 0pt"><SPAN lang=EN-US><FONT size=3><SPAN style="mso-spacerun: yes"> </SPAN>TSCR1=0x00;</FONT></SPAN></P><P class=MsoNormal style="MARGIN: 0pt"><SPAN lang=EN-US><FONT size=3><SPAN style="mso-spacerun: yes"> </SPAN>PORTB=0x7E;</FONT></SPAN></P><P class=MsoNormal style="MARGIN: 0pt"><SPAN lang=EN-US><FONT size=3>}</FONT></SPAN></P><P>这个在每次运行后寄存器TCNT里的值为什么每次都不一样?用单步运行时也是每次数值都不一样 这是怎么回事?</P>
作者:
haohaohun
时间:
2008-4-25 06:55
标题:
Re:关于定时和测速的问题
<
>你把 Init_INT_Timer();<BR>放到for(;;)循环</P><P>外面再试试</P>
作者:
yanglei05260
时间:
2008-5-9 00:41
标题:
Re:关于定时和测速的问题
还是不行啊,的继续努力了!
作者:
liuchangyin
时间:
2008-6-24 04:51
标题:
Re:关于定时和测速的问题
用主定时器看看,我们就用的是主定时器
作者:
LJG
时间:
2012-3-3 22:20
欢迎光临 智能车制作 (http://dns.znczz.com/)
Powered by Discuz! X3.2