I
import
Unregistered / Unconfirmed
GUEST, unregistred user!
sound: procedure BeepEx(feq:word=1200;delay:word=1);
procedure BeepOff;
begin
asm
in al,$61;
and al,$fc;
out $61,al;
end;
end;
const
scale=1193180;
var
temp:word;
begin
temp:=scale div feq;
asm
in al,61h;
or al,3;
out 61h,al;
mov al,$b6;
out 43h,al;
mov ax,temp;
out 42h,al;
mov al,ah;
out 42h,al;
end;
sleep(delay);
beepoff;
end;
用嵌入汇编的方式,
下面是我在C++Builder编的扬声器发声片段,
与DELPHI 是姐妹语言, 我想可能差不多,
供你参考.
void Sound(int f) // 发音, 频率f
{
__int16 B=1193180/f;
asm in AL,61H; // 从端口B取数
asm or AL,3; // 两低位置1
asm out 61H,AL; // 返给端口B
asm mov AL,0B6H; // 通道2位图,2B,M3,B2
asm out 43H,AL; // 送指令寄存器
asm mov AX,B; // 计数: 1193180/F
asm out 42H,AL; // 送低有效位LSB
asm mov AL,AH;
asm out 42H,AL; // 送高有效位MSB
}
void SoundOff() // 关闭声音
{
asm in AL,61H; // 取端口B的字节
asm and AL,0FCH; // 强制置两位为0
asm out 61H,AL; // 返送端口B
}
procedure BeepOff;
begin
asm
in al,$61;
and al,$fc;
out $61,al;
end;
end;
const
scale=1193180;
var
temp:word;
begin
temp:=scale div feq;
asm
in al,61h;
or al,3;
out 61h,al;
mov al,$b6;
out 43h,al;
mov ax,temp;
out 42h,al;
mov al,ah;
out 42h,al;
end;
sleep(delay);
beepoff;
end;
用嵌入汇编的方式,
下面是我在C++Builder编的扬声器发声片段,
与DELPHI 是姐妹语言, 我想可能差不多,
供你参考.
void Sound(int f) // 发音, 频率f
{
__int16 B=1193180/f;
asm in AL,61H; // 从端口B取数
asm or AL,3; // 两低位置1
asm out 61H,AL; // 返给端口B
asm mov AL,0B6H; // 通道2位图,2B,M3,B2
asm out 43H,AL; // 送指令寄存器
asm mov AX,B; // 计数: 1193180/F
asm out 42H,AL; // 送低有效位LSB
asm mov AL,AH;
asm out 42H,AL; // 送高有效位MSB
}
void SoundOff() // 关闭声音
{
asm in AL,61H; // 取端口B的字节
asm and AL,0FCH; // 强制置两位为0
asm out 61H,AL; // 返送端口B
}