Abl-electronic PIC Microcontrollers PIC16 Manuel d'utilisateur Page 273

  • Télécharger
  • Ajouter à mon manuel
  • Imprimer
  • Page
    / 312
  • Table des matières
  • MARQUE LIVRES
  • Noté. / 5. Basé sur avis des utilisateurs
Vue de la page 272
The example is a simple demonstration of how to use sound library for playing
tones on a piezo speaker. The code can be used with any MCU that has PORTB
and ADC on PORTA. Sound frequencies in this example are generated by reading
the value from ADC and using the lower byte of the result as base for T (f = 1/T).
MikroElektronika:
Development
tools
-
Books
-
Compilers
265
page
mikroC
- C Compiler for Microchip PIC microcontrollers
mikroC
making it simple...
Library Example
int adcValue;
void main() {
PORTB = 0;
// Clear PORTB
TRISB = 0;
// PORTB is output
INTCON = 0;
// Disable all interrupts
ADCON1 = 0x82;
// Configure VDD as Vref, and analog channels
TRISA = 0xFF;
// PORTA is input
Sound_Init(PORTB, 2);
// Initialize sound on RB2
while (1) {
// Play in loop:
adcValue = ADC_Read(2);
// Get lower byte from ADC
Sound_Play(adcValue, 200);
// Play the sound
}
}
Vue de la page 272
1 2 ... 268 269 270 271 272 273 274 275 276 277 278 ... 311 312

Commentaires sur ces manuels

Pas de commentaire