智能车制作

标题: 测速及显示 [打印本页]

作者: weicheng259    时间: 2008-12-11 20:46
标题: 测速及显示
<>我写的测速及显示在一块板子上有结果,换了块板子就不行了!单步运行时进不了中断,其中一块板子可以!(我用的是MC9SDG128开发板)</P><P>请帮我解决下!!?</P><P>///////////////////////////////////////////////////////////////////<BR>//PT4输入捕捉测速程序,PT4口输入脉冲<BR>//说明此程序用于总线时钟在8M情况下,若总线时钟有变化,改分频参数和模数常数以得到精确定时<BR>///////////////////////////////////////////////////////////////////<BR>#include &lt;hidef.h&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&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"</P><P>#define TIME_INTER 500&nbsp;&nbsp;&nbsp; <BR>unsigned int Get_pulse;&nbsp;&nbsp;&nbsp; //脉冲个数<BR>unsigned int V;<BR>unsigned int number_count;<BR>unsigned char LED[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};<BR>unsigned char i,j;<BR>unsigned int data[4];<BR>unsigned char dat[]={0x70,0xB0,0xD0,0xE0};</P><P><BR>void main(void) <BR>{&nbsp; DDRA=0xff;<BR>&nbsp;&nbsp; PORTA=0x00;<BR>&nbsp;&nbsp; DDRM=0XFF;<BR>&nbsp;&nbsp; PTM=0X00;<BR>&nbsp;&nbsp;&nbsp; DisableInterrupts;<BR>&nbsp;&nbsp; PWM_Init() ;<BR>&nbsp;&nbsp; TIOS=0x00;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //输入捕捉<BR>&nbsp;&nbsp; TCTL3=0x02;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //通道4下降沿触发<BR>&nbsp;&nbsp; TSCR2=0X07;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //分频,用来给TCNT作时间参考<BR>&nbsp;&nbsp; TSCR1=0x80;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //Timer Enable<BR>&nbsp;&nbsp; TIE=0X10;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //初始化定时器开启<BR>&nbsp;&nbsp; TFLG1=0x10; <BR>&nbsp;&nbsp; MCFLG_MCZF=1;<BR>&nbsp;&nbsp; MCCTL = MCCTL&amp;0Xfb;&nbsp; //模数计数器禁止运行<BR>&nbsp;&nbsp; MCCTL = 0Xe3;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //允许中断,模数计数方式 返回时重新加载所用的常数,分频常数为16 <BR>&nbsp;&nbsp; MCCTL = MCCTL|0X04;&nbsp; //模数计数器使能<BR>&nbsp;&nbsp; MCCNT = 1000;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //(1/16M)*8*1000 <BR>&nbsp;&nbsp; MCCTL = MCCTL|0X08 ; //把模数常数寄存器的值加载到模数计数器FLMC;<BR>&nbsp;&nbsp; EnableInterrupts;<BR>&nbsp;&nbsp; for(;;)<BR>&nbsp;&nbsp; { for(i=0;i&lt;3;i++)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {V=Get_pulse*21;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; data[2]=V/1000;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; data[1]=(V/100)%10;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; data[0]=((V/10)%10);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //data[0]=V%10;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; PTM=dat<i>;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; PORTA=LED[data<i>];<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for(j=0;j&lt;20;j++);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } <BR>}</P><P><BR>#pragma CODE_SEG&nbsp; NON_BANKED<BR>void interrupt 26 MDC_ISR(void) <BR>{ <BR>&nbsp; static unsigned int count=0;<BR>&nbsp; count++;<BR>&nbsp; if( count==TIME_INTER)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //1秒取一次<BR>&nbsp;&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Get_pulse = number_count;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; number_count=0;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; count=0;<BR>&nbsp;&nbsp;&nbsp;&nbsp; }<BR>&nbsp;&nbsp; <BR>&nbsp; MCFLG = 0x80;<BR>&nbsp;}</P><P><BR>void interrupt 12 PT4_Capture(void) <BR>{ <BR>&nbsp; TFLG1=0x10; <BR>&nbsp; number_count++;<BR>}</P><P><BR>&nbsp;</P>
作者: chiusir    时间: 2008-12-11 22:55
标题: Re:测速及显示
你参考一下我的IOC的例程,加上时钟中断,应该可以搞定
作者: whut_wj    时间: 2008-12-12 03:07
标题: Re:测速及显示
<>显示在一块板子上有结果,那么最有可能是板子问题.</P><P>可能的话,找第三块板子试一下.</P><P>这个程序相当简单的,</P>




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