Attiny13a buzzer example

In this example we connect a piezo buzzer to PB0 of our Attiny13a. We use mikroC pro for AVR which has a built in sound library to play a tone

 

Schematic

attiny13 and piezo

attiny13 and piezo

Code

As stated earlier we use mikroC pro for AVR, this contains a sound library.

void main()
{ 
DDRB = 0x00; // Configure PORTB as input
Sound_Init(&PORTB,0); // Initialize sound pin
while (1) 
{ // endless loop
Sound_Play(659, 250); //
delay_ms(2000);
}
}

Links
5Pcs ATTINY13A-PU AVR Microcontroller Flash 20MHZ

20 PCS piezo buzzer