Sends pulses to a port pin.
SOUND pin, duration, frequency [,NOINT]
Any I/O pin such as P1.0 etc.
This is an integer, word or constant that specifies how long the sound is generated. A bigger value will result in a longer duration of the sound.
This is an integer, word, or constant that that will be used to generate the frequency. A higher value will result in a higher frequency. A very low value might result in a sound that can not be heard.
An option to disable interrupts during the sound statement.
The SOUNDEXT should be used instead of the SOUND statement. It has a wider range.
When you connect a speaker or a buzzer to a port pin (see hardware) , you can use the SOUNDEXT statement to generate some tones.
The NOINT will clear the global interrupts so no interrupts can occur during the sound statement. When the sound statement has completed the interrupt register is restored.
The SoundExt routine will create the sound as following:
|The port pin is set LOW
|The specified frequency is inverted
|The inverted value is decreased
|The port pin is set HIGH
|The inverted value is restored and decreased again
The actions are executed for DURATION times.
When the statement is ready, it will leave the pin in the HIGH state.
The time the pin is low is exact the same time as the pin is high. So the created pulse width is 50%.
Since loops are used, the frequency is relatively to the processor speed.
The width range of the frequency will ensure that you can create hearable tones width a variety of oscillator values. When you want to create tones that are independent of the processor speed, you need to use a timer.
$regfile = "89s4051.dat"
$crystal = 8000000
Dim X As Word
X = 0
X = X - 10
Soundext P3.4 , 500 , X