Advertisement
Guest User

Untitled

a guest
Jun 23rd, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. #include <avr/io.h>
  2. #include <util/delay.h>
  3.  
  4. // Macro
  5. #define BEEPON 127
  6. #define BEEPOFF 0
  7. #define TRUE 1
  8. #define FALSE 0
  9. #define STDBEEP OCR0A = BEEPON; _delay_ms(500); OCR0A=BEEPOFF;
  10.  
  11.  
  12. static void init(void);
  13.  
  14. int main(void)
  15. {
  16. init();
  17. int done = FALSE;
  18. while(1)
  19. {
  20. if(PINB & 0x02)
  21. {
  22. while (!done)
  23. {
  24. STDBEEP;
  25. _delay_ms(1000);
  26.  
  27. STDBEEP;
  28. _delay_ms(750);
  29.  
  30. STDBEEP;
  31. _delay_ms(500);
  32.  
  33. STDBEEP;
  34. _delay_ms(250);
  35.  
  36. STDBEEP;
  37. _delay_ms(100);
  38.  
  39. STDBEEP;
  40. _delay_ms(100);
  41.  
  42. STDBEEP;
  43. _delay_ms(50);
  44.  
  45. STDBEEP;
  46. _delay_ms(25);
  47.  
  48. // Last beep
  49. OCR0A = BEEPON;
  50. _delay_ms(1000);
  51. OCR0A = BEEPOFF;
  52. done = TRUE;
  53. }
  54. }
  55. }
  56. return 1;
  57. }
  58.  
  59. static void init(void)
  60. {
  61. // Data Direction
  62. // PB1(Pin 6): PWM Output
  63. // PB2(Pin 7): Button Input
  64. DDRB = 0x01;
  65. //PINB = 0x02;
  66. PORTB = 0x00;
  67.  
  68. // PWM Setup
  69. TCCR0A = 0x82;
  70. TCCR0B = 0x02;
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement