Guest User

Untitled

a guest
Jun 25th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.87 KB | None | 0 0
  1. #include <avr/io.h>
  2. #include <avr/interrupt.h>
  3. #include <util/delay.h>
  4.  
  5.  
  6. volatile unsigned int namerane;
  7.  
  8. // akcia Input Capture
  9. ISR (TIMER1_CAPT_vect){
  10.     namerane = TCNT1;
  11.     TCNT1 = 0;
  12. }
  13.  
  14.  
  15. int main(){
  16.  
  17.     unsigned char blik;
  18.  
  19.     DDRD |= (1 << PD7);  // PD7 ako výstupný
  20.    
  21.     DDRB &= ~(1 << PB0); // PB0 (ICP1) ako vstupny
  22.     PORTB |= (1 << PB0); //PB0 (ICP1) do log.1
  23.  
  24.     TCCR1B |= (1 << CS12) | (1 << CS10); //preddelička 1024 (128us)
  25.     TIMSK |= (1 << TICIE1); // prerušenie na udalost Input Capture
  26.    
  27.     OSCCAL = 0xA5;    // nastavenie kalibracneho bajtu interneho RC oscilatora
  28.        
  29.     sei(); // povol globalne prerušenia
  30.  
  31.     while(1){   // nekonečná slučka
  32.  
  33.         if(namerane) {
  34.        
  35.             for(blik=0;blik < (namerane/7812);blik++){
  36.             PORTD |= (1 << PD7);
  37.             _delay_ms(200);
  38.             PORTD &= ~(1 << PD7);
  39.             _delay_ms(200);
  40.             }
  41.  
  42.         namerane = 0;
  43.         }
  44.  
  45.     }
  46.  
  47. return 0;
  48. }
Add Comment
Please, Sign In to add comment