Hardware Reference
In-Depth Information
print "Enter frequency in the range 100Hz to 5000HZ"
do
locate 6, 1
print blank$
locate 6, 1
print "Frequency (Hz) or <return> to quit: ";
input freq$
if freq$ = "" then call stopsound: end
freq% = val(freq$)
if freq% > 99 and freq% < 5001 then
call speaker(freq%)
locate 5, 1
print blank$
locate 5, 1
print "Current frequency = ";freq%;"Hz"
end if
loop
'
' Assembly language routines
'
function speaker(BYVAL freq%)
count% = 1190000/freq%
asm in al, &H61
asm or al, &H03
asm out &H61, al
asm mov al, &Hb6
asm out &H43, al
asm mov ax, count%
asm out &H42, al
asm mov al, ah
asm out &H42, al
end function
'
sub stopsound
asm
in al, &H61
asm
and al, &Hfc
asm
out &H61, al
end sub
There are two important things to note from this example. Firstly, each line
of assembly language code is preceded by the
asm
keyword. Secondly, the
assembly language code has direct access to BASIC variables (such as
count%
).
Figure 6.6
Output produced by the PowerBASIC 3.5 speaker demonstration
program