Subdomain Posts
C | 7 days ago
C | 7 days ago
C | 18 days ago
C++ | 81 days ago
C | 173 days ago
C | 173 days ago
C | 178 days ago
C | 178 days ago
Recent Posts
None | 14 sec ago
None | 17 sec ago
None | 21 sec ago
None | 44 sec ago
C++ | 49 sec ago
PAWN | 54 sec ago
ActionScript | 56 sec ago
None | 1 min ago
What is pastebin?
Pastebin is a website that hosts all your text & code on dedicated servers for easy sharing.
learn more...
Domain Reports
By Nerdful_com on the 17th of Aug 2009 06:49:28 PM
Download |
Raw |
Embed |
Report
/*
Make music with piezo (piezoelectric buzzer).
Put the buzzer on MCU pin 15 (PB1)
Does not use libnerdkits in makefile use # to comment out makefile lines related
Hacked by www.Nerdful.com
*/
#define F_CPU 8000000UL // 8MHz
#include <avr/io.h>
#include <util/delay.h>
void play_tone(uint16_t delay, uint8_t duration) {
uint16_t tmp = 100 * duration;
uint16_t delaysm = delay / 50;
uint16_t cycles = tmp / delaysm;
while(cycles > 0) {
PORTB |= (1<<PB1);
_delay_us(delay);
PORTB &= ~(1<<PB1);
_delay_us(delay);
cycles--;
}
}
int main() {
// oscillator @ 8MHz.
OSCCAL = 176;
DDRB |= (1<<PB1);
while(1) {
play_tone(1000, 50);
play_tone(950, 50);
play_tone(900, 50);
play_tone(850, 50);
play_tone(800, 50);
play_tone(750, 50);
play_tone(700, 50);
play_tone(650, 50);
play_tone(600, 50);
play_tone(550, 50);
play_tone(500, 50);
play_tone(450, 50);
play_tone(400, 50);
play_tone(350, 50);
play_tone(300, 50);
play_tone(250, 50);
_delay_ms(2000);
}
return 0;
}
Submit a correction or amendment below.
Make A New Post