Advertisement
Guest User

Untitled

a guest
Jun 23rd, 2017
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.07 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.  
  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.                 OCR1B = BEEPON;
  50.                 _delay_ms(1000);
  51.                 OCR1B = 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.     //TCCR1 = 0x58;
  70.     //PLLCSR = 0x82;
  71.     //GTCCR = 0x00;
  72.     //PLLCSR |= 0x01;
  73.     TCCR0A = _BV(WGM00) | _BV(COM0A1) | _BV(COM0B1);
  74.     TCCR0B |= _BV(CS01);
  75.      
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement