这个简单,AD/DA转换的时间是纳秒级的,关键是你的延时的处理。<br><br>我这里将去年做的东西的一个模块贴出来,建议你将延时用For循环来代替。<br><br>这样的速度非常高<br><br>{ -----------------------------------------------------------------------------}<br>{ 更新日期: 22/4/2002 <br> 作者:司马华鹏}<br>{ -----------------------------------------------------------------------------} <br>{ 多线程采集与多线程绘制模块 }<br>{------------------------------------------------------------------------------}<br><br>unit UnitTThread;<br><br>interface<br><br>uses<br> Classes, Windows, Sysutils,Graphics,SyncObjs;<br><br>const<br> Pie:Single=3.14159;<br> <br>type<br> //采集线程<br> TCollectThread = class(TThread)<br> private<br> W,H:integer;<br> procedure DoPaint; //绘制仿真动画<br> function ChangeAngle(xOld,yOld:integer;Rotation:single):Tpoint;//角度旋转转换<br> procedure PlaySound(le_son : pchar);//播放资源文件中的声音<br> protected<br> procedure Execute; override;<br> public<br> constructor Create;//构造函数<br> end;<br><br>implementation<br><br>uses UnitMain,UnitAD,MMsystem;<br><br>{------------------------------------------------------------------------------}<br>{----采集线程----}<br>{------------------------------------------------------------------------------}<br>Constructor TCollectThread.Create;//构造函数<br>begin<br> W:=frmMain.imgPlay.Width;<br> H:=frmMain.imgPlay.Height;<br> FreeOnTerminate:=True; //退出时自动释放<br> inherited Create(False); //创建即可运行<br>end;<br><br>procedure TCollectThread.Execute;//执行函数<br>var<br> V:single;//电压值<br> H,L:Byte;//高位、低位<br> K:Byte;<br>begin<br> while not Terminated do begin<br><br> PortWriteByte($100,0); //初始化 outp(0x100,0);<br> PortWriteByte($101,0); //开始转换 outp(0x101,0);<br><br> repeat<br> K:=(PortReadByte($101) and 1); //k=intp(0x101) & 1<br> until (k=0); //软件查询(基于转换速度) //if (k==0) <br><br> H:=PortReadByte($102); // intp(0x102);<br> L:=PortReadByte($103); // intp(0x103);<br> <br> V:=10*(H*16+L/16)/4096-5;//转换为电压信号<br> <br> iAngle:=V*2;//转换为角度信息(角度值)<br><br> if iAngle>=5 then PlaySound('Wrong');//发出警告<br> <br> Synchronize(DoPaint);//绘图<br> end;<br>end;<br><br>procedure TCollectThread.doPaint;//绘图<br>var<br> P: Array[0..3] of TPoint;<br> R:TRect;<br> strTmp:string;<br> sglTmp:single;<br>begin<br><br> strTmp:=Floattostr(iAngle); //浮点型转换为字符型<br> sglTmp:=iAngle*Pie/180; //角度转弧度<br> <br> with frmMain.imgPlay do begin//使用双缓冲<br> Canvas.FillRect(Canvas.ClipRect);//刷新<br> P[0]:=ChangeAngle(40,20,sglTmp);<br> P[1]:=ChangeAngle(40,H-60,sglTmp);<br> P[2]:=ChangeAngle(W-40,H-60,sglTmp);<br> P[3]:=ChangeAngle(W-40,20,sglTmp);<br> Canvas.Polygon(P);//画小车<br><br> R.Left:=75;<br> R.Top:=H-60;<br> R.Right:=W-75;<br> R.Bottom:=H-30;<br> Canvas.Ellipse(R);//画圆形<br><br> SetBkMode(Canvas.Handle,1);//透明字体<br> Canvas.TextOut((W-Canvas.TextWidth(strTmp)) div 2,H-20,strTmp);//打印角度<br> end;<br><br> frmMain.pbMain.Invalidate;<br>end;<br><br>//角度旋转变换<br>function TCollectThread.ChangeAngle(xOld,yOld:integer;Rotation:single):Tpoint;<br>var<br> cX,cY:integer;<br>begin<br> cX:=W div 2;<br> cY:=H -15;<br> Result.X:=Round((xOld-cX)*cos(Rotation)-(cY-yOld)*sin(Rotation)+cX);<br> Result.Y:=Round(cy-(xOld-cx)*sin(Rotation)-(cY-yOld)*cos(Rotation));<br>end;<br><br>//播放资源文件中的声音<br>procedure TCollectThread.PlaySound(le_son : pchar);<br>var<br> h: THandle;<br> p: pointer;<br>begin<br> h := FindResource(hInstance,le_son,'WAV');<br> h := LoadResource(hInstance, h);<br> p := LockResource(h);<br> sndPlaySound(p,SND_MEMORY or SND_ASYNC);<br> UnLockResource(h);<br> FreeResource(h);<br>end; <br>end.<br>