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
Please check out our new and improved Firefox Add-on. hide message
By Nerdful_com on the 17th of Aug 2009 06:49:28 PM Download | Raw | Embed | Report
  1. /*
  2. Make music with piezo (piezoelectric buzzer).
  3. Put the buzzer on MCU pin 15 (PB1)
  4. Does not use libnerdkits in makefile use # to comment out makefile lines related
  5. Hacked by www.Nerdful.com
  6. */
  7. #define F_CPU 8000000UL // 8MHz
  8. #include <avr/io.h>
  9. #include <util/delay.h>
  10. void play_tone(uint16_t delay, uint8_t duration) {
  11.   uint16_t tmp = 100 * duration;
  12.   uint16_t delaysm = delay / 50;
  13.   uint16_t cycles = tmp / delaysm;
  14.  
  15.   while(cycles > 0) {
  16.     PORTB |= (1<<PB1);
  17.     _delay_us(delay);
  18.     PORTB &= ~(1<<PB1);
  19.     _delay_us(delay);
  20.     cycles--;
  21.   }
  22. }
  23. int main() {
  24. // oscillator @ 8MHz.
  25. OSCCAL = 176;
  26. DDRB |= (1<<PB1);
  27. while(1) {
  28. play_tone(1000, 50);
  29. play_tone(950, 50);
  30. play_tone(900, 50);
  31. play_tone(850, 50);
  32. play_tone(800, 50);
  33. play_tone(750, 50);
  34. play_tone(700, 50);
  35. play_tone(650, 50);
  36. play_tone(600, 50);
  37. play_tone(550, 50);
  38. play_tone(500, 50);
  39. play_tone(450, 50);
  40. play_tone(400, 50);
  41. play_tone(350, 50);
  42. play_tone(300, 50);
  43. play_tone(250, 50);
  44. _delay_ms(2000);
  45. }
  46. return 0;
  47. }
Submit a correction or amendment below. Make A New Post
To highlight particular lines, prefix each line with @h@
Syntax highlighting:
Post expiration:
Post exposure:
Name / Title:
Email: