给你一个函数<br>function _GetPort(address:word):word;//获取端口<br>var bValue: byte;<br>begin<br> asm<br> mov dx, address<br> in al, dx<br> mov bValue, al<br> end;<br> Result := bValue;<br>end;<br><br>procedure _SetPort(address, Value:Word);//设置端口<br>var bValue: byte;<br>begin<br> bValue := Trunc(Value and 255);<br> asm<br> mov dx, address<br> mov al, bValue<br> out dx, al<br> end;<br>end;<br><br>procedure StartBeep(Freq : Word);//开始发音,Freq为频率<br>var<br> B: Byte;<br>begin<br> if Freq > 18 then<br> begin<br> Freq := Word(1193181 div LongInt(Freq));<br> B := Byte(_GetPort($61));<br> if (B and 3) = 0 then<br> begin<br> _SetPort($61, Word(B or 3));<br> _SetPort($43, $B6);<br> end;<br> _SetPort($42, Freq);<br> _SetPort($42, Freq shr 8);<br> end;<br>end;<br><br>procedure StopBeep;//停止发音<br>var<br> Value: Word;<br>begin<br> value := _GetPort($61) and $FC;<br> _SetPort($61, Value);<br>end;<br><br>