Andrei_M

LAB WORK 3

Nov 11th, 2019
260
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.88 KB | None | 0 0
  1. /*
  2.  * 3.c
  3.  *
  4.  * Created: 05.11.2019 13:53:30
  5.  * Author : dspproject
  6.  */
  7. #define F_CPU 14745600UL
  8.  
  9.  
  10. #include <avr/io.h>
  11. #include <avr/interrupt.h>
  12. #include <util/delay.h>
  13.  
  14. void init_timer()
  15. {
  16.     unsigned value = 18; //asta ii OCR1A , grija la virgula
  17.    
  18.     OCR1AH = (value >> 8) & 0xFF;
  19.     OCR1AL = (value & 0xFF);
  20.    
  21.     TCCR1B = 1 << 3; //mode 4
  22.     TCCR1B |= 1 << 1; // clk pt asta trebuie sa fie 1 (CS11 = 1)
  23.     //OCR1A = value;
  24. }
  25.  
  26. int main(void)
  27. {
  28.     /* Replace with your application code */
  29.     DDRB |= 1;
  30.     init_timer();
  31.     int x = 0;
  32.    
  33.     while (1)
  34.     {
  35.        
  36.        
  37.         if((TIFR & (1 << 4)) != 0) //tifr arata cand a ajuns la capat, un fel de ct
  38.         {
  39.             //aprinde led
  40.             if(x)
  41.                 PORTB |= 1;
  42.             //_delay_ms(200);
  43.             else
  44.                 PORTB = 0;
  45.             //_delay_ms(200);
  46.             x = x ? 0 : 1;
  47.             TIFR |= 1 << 4; //asa ii facut, sa se reseteze cand il punem pe 1 ( siguranta++)
  48.         }
  49.     }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment