Advertisement
Guest User

Untitled

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