由于CCS的编译优化,使得采用NOP延时的老办法无效。如下是一个成熟的方法。<br /><br />方法:用DM642的定时器2作精确延时。<br />效果:应用在成熟产品中,很可靠并支持重入机制。<br />程序:如下<br /><br />/////////////////////////////////////////////////////////////////////<br />// function: Wait_uSeccond<br />// <br />// Descript: Spin in a delay loop for delay microseconds<br />// Note: (1) Timer-2 does not trig a interrupt.<br />// (2) The MAX time is 57.2662306 seconds at CPU clock 600 MHz.<br />// (3) 1uS = 75 cycle.<br />//////////////////////////////////////////////////////////////////////<br />void Wait_uSeccond( Uint32 ui32Delay)<br />{<br /> Uint32 cnt;<br /> TIMER_Config cfgTimer2;<br /><br /> // save Timer2 old settings<br /> TIMER_getConfig( hTimer2, &cfgTimer2);<br /><br /> cnt = 75*ui32Delay;<br /><br /> // clear the timer count register<br /> TIMER_setCount( hTimer2, 0x00000000);<br /><br /> // resume the timer2<br /> TIMER_resume( hTimer2);<br /><br /> // wait until time=delay<br /> while( TIMER_getCount( hTimer2) < cnt);<br /><br /> // Reconfigure Timer2 with old settings<br /> TIMER_config( hTimer2, &cfgTimer2);<br />}<br />
|