Mikroelektronika MIKROE-724 データシート

ページ / 726
464
mikoBasic PRO for dsPIC30/33 and PIC24
MikroElektronika
Sound Library
mikroBasic PRO for dsPIC30/33 and PIC24 provides a Sound Library to supply users with routines necessary for sound 
signalization in their applications. Sound generation needs additional hardware, such as piezo-speaker (example of 
piezo-speaker interface is given on the schematic at the bottom of this page).
Library Routines
 
- Sound_Init 
 
- Sound_Play 
Sound_Init
Sound_Play
Prototype
sub procedure Sound_Init(dim byref snd_port, snd_pin as word)
Description Configures the appropriate MCU pin for sound generation.
Parameters 
snd_port
: sound output port address 
snd_pin
: sound output pin 
Returns
Nothing.
Requires
Nothing. 
Example
‘ Initialize the pin RD3 for playing sound
Sound_Init(PORTD, 3)
Notes
None.
Prototype
sub procedure Sound_Play(dim freq_in_hz, duration_ms as word)
Description Generates the square wave signal on the appropriate pin.
Parameters 
freq_in_hz
: signal frequency in Hertz (Hz) 
duration_ms
: signal duration in miliseconds (ms) 
Returns
Nothing.
Requires
In order to hear the sound, you need a piezo speaker (or other hardware) on designated port. Also, you 
must call Sound_Init to prepare hardware for output before using this function.
Example
‘ Play sound of 1KHz in duration of 100ms
Sound_Play(1000, 100)
Notes
None.