Advertisement
Ostu

Untitled

Mar 28th, 2021
2,234
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <avr/io.h>
  2. #include <avr/interrupt.h>
  3.  
  4. #define czas 130
  5.  
  6. unsigned char a;
  7.  
  8. int main(void)
  9. {
  10.     DDRA=0xFF;
  11.     a=20;
  12.     TCCR0=(1<<CS02)|(1<<CS00)|(1<<WGM01);   //preskaler 1024 tryb CTC
  13.     OCR0=czas;  // przypisanie stałej do rejestru OCR0
  14.     TIMSK|=(1<<OCIE0);  // odblokowanie przerwania od zrównania rejestrów TCNT0 i OCR0
  15.  
  16.     sei(); // globalne zezwolenie na przerwania
  17.  
  18.     while(1);
  19. }
  20.  
  21. ISR(TIMER0_COMP_vect)
  22. {
  23.     a--;
  24.     if(a==0)
  25.     {
  26.         a=20;
  27.         PORTA^=0xFF; // negacja bitowa
  28.     }
  29. }
  30.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement