Mikroelektronika MIKROE-742 데이터 시트

다운로드
페이지 532
Sound_Play
Library Example
The example is a simple demonstration of how to use the Sound Library for playing tones on a
piezo speaker.
program Sound;
// Sound connections
var Sound_Play_Pin : sbit at PORTC.B3;
var Sound_Play_Pin_direction : sbit at DDRC.B3;
// End Sound connections
procedure Tone1();
begin
Sound_Play(500, 200);               // Frequency = 500Hz, Duration = 200ms
end;
procedure Tone2();
begin
Sound_Play(555, 200);               // Frequency = 555Hz, Duration = 200ms
end;
procedure Tone3();
begin
Sound_Play(625, 200);               // Frequency = 625Hz, Duration = 200ms
end;
procedure Melody();                          // Plays the melody "Yellow house"
begin
Tone1(); Tone2(); Tone3(); Tone3();
371
MIKROELEKTRONIKA
- SOFTWARE AND HARDWARE SOLUTIONS FOR EMBEDDED WORLD
Libraries
mikroPASCAL PRO for AVR
CHAPTER 6
Prototype
procedure Sound_Play(freq_in_Hz: word; duration_ms: 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);