mikroC

mikroC - C Compiler for Microchip PIC microcontrollers

making it simple...

Sound Library

mikroC provides a Sound Library which allows you to use sound signalization in your applications. You need a simple piezo speaker (or other hardware) on designated port.

Library Routines

Sound_Init

Sound_Play

Sound_Init

Prototype

void Sound_Init(char *port, char pin);

Description Prepares hardware for output at specified port and pin. Parameter pin needs to be within range 0–7.

Example

Sound_Init(PORTB, 2); // Initialize sound on RB2

Sound_Play

Prototype

void Sound_Play(char period_div_10, unsigned num_of_periods);

Description Plays the sound at the specified port and pin (see Sound_Init). Parameter period_div_10 is a sound period given in MCU cycles divided by ten, and generated sound lasts for a specified number of periods (num_of_periods).

Requires 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.

Example To play sound of 1KHz: T = 1/f = 1ms = 1000 cycles @ 4MHz. This gives us our first parameter: 1000/10 = 100. Play 150 periods like this:

Sound_Play(100, 150);

page

 

264

MikroElektronika: Development tools - Books - Compilers