uwezi

20221215_attiny_blinky

Dec 15th, 2022
1,761
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.71 KB | None | 0 0
  1. #include <avr/io.h>
  2. #include <util/delay.h>
  3. // LED på OCR0A
  4.  
  5. int main(void)
  6. {
  7.   TCCR0A = (1 << COM0A1) | (0 << COM0A0)
  8.           | (0 << COM0B1) | (0 << COM0B0)
  9.           | (1 << WGM01) | (1 << WGM00);
  10.   TCCR0B = (0 << WGM02)
  11.           | (0 << CS02) | (1 << CS01) | (0 << CS00);
  12.   OCR0A = 0;
  13.   DDRB |= (1 << PB0);
  14.  
  15.   uint8_t dir = 1;
  16.  
  17.   while (1)
  18.   {
  19.     if (dir)
  20.     {
  21.       if (OCR0A <= 254)
  22.       {
  23.         OCR0A += 1;
  24.       }
  25.       else
  26.       {
  27.         OCR0A = 255;
  28.         dir = 0;
  29.       }
  30.     }
  31.     else
  32.     {
  33.       if (OCR0A >= 1)
  34.       {
  35.         OCR0A -= 1;
  36.       }
  37.       else
  38.       {
  39.         OCR0A = 0;
  40.         dir = 1;
  41.       }
  42.     }
  43.     _delay_ms(10);
  44.   }          
  45. }
Advertisement
Add Comment
Please, Sign In to add comment