Advertisement
Guest User

Untitled

a guest
Nov 21st, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.61 KB | None | 0 0
  1. #include<avr/io.h>
  2. #include<avr/delay.h>
  3. #include <avr/interrupt.h>  
  4. #define F_CPU 1000000L
  5. void main()
  6. {
  7.     TCCR0 = ((1<<COM01) | (1<<COM00) | (1<<WGM01) | (1<<WGM00) | (1<<CS01));
  8.     TCNT0 = 0;
  9.     DDRB = _BV(3);
  10.     OCR0 = 0;
  11.     int dec = 0;
  12.  
  13.     int counter = 0;
  14.     PORTA = _BV(3);
  15.  
  16.     while(1==1)
  17.     {
  18.         if(TIFR & (1 << OCF0))
  19.         {
  20.             //TIFR |= 1<<OCF0;
  21.             counter++;
  22.            
  23.  
  24.             if(counter == 3000)
  25.             {
  26.                 if(OCR0 == 0)
  27.                     dec = 0;
  28.                 if(OCR0 == 255)
  29.                     dec = 1;
  30.  
  31.                 if(dec)
  32.                     OCR0 -= 5;
  33.                 else
  34.                     OCR0 += 5;
  35.                 counter = 0;
  36.             }
  37.         }
  38.     }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement