Mikroelektronika MIKROE-350 Datenbogen

Seite von 526
Sound_Init
Sound_Play
358
MIKROELEKTRONIKA
- SOFTWARE AND HARDWARE SOLUTIONS FOR EMBEDDED WORLD
Libraries
mikroBasic PRO for AVR
CHAPTER 6
Prototype
sub procedure Sound_Init()
Returns
Nothing.
Description
Configures the appropriate MCU pin for sound generation.
Requires
Global variables: 
Sound_Play_Pin:
Sound output pin 
Sound_Play_Pin_Direction:
Direction of the Sound output pin 
must be defined before using this function.
Example
' Sound library connections
dim Sound_Play_Pin  as sbit at PORTC.B3
dim Sound_Play_Pin_Direction  as sbit at DDRC.B3
' End of Sound library connections
...
Sound_Init()
Prototype
sub procedure Sound_Play(dim freq_in_Hz as worddim duration_ms
as word)
Returns
Nothing.
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) 
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)