Advertisement
Andrei_M

Interrupt LAB WORK 4

Nov 25th, 2019
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.16 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. int x = 0;
  14. int ev = 0;
  15.  
  16. ISR(TIMER1_COMPA_vect) //subrutina daca interupt
  17. {
  18.     ev = 1;
  19. }
  20.  
  21. void init_timer()
  22. {
  23.     unsigned value = 18; //asta ii OCR1A , grija la virgula
  24.    
  25.     OCR1AH = (value >> 8) & 0xFF;  //OCRA impartit in 2 registre => adaugi MSB half aici
  26.     OCR1AL = (value & 0xFF);   //LS half aici
  27.    
  28.     TCCR1B = 1 << 3; //mode 4
  29.     TCCR1B |= 1 << 1; // clk pt asta trebuie sa fie 1 (CS11 = 1)
  30.     TIMSK |= 1<<4;
  31. /* 
  32.     if((OCIE1A & (1<<4)) == 1 ) //verifica daca flagul pt interuperi ii 1
  33.     {
  34.         ISR(TIMER1_COMPA_vect);
  35.     }*/ // nu mai trebuie verificat, fiind flagul setat mai sus, la TIMSK, o sa faca singur subrutina de sus
  36.     //OCR1A = value;
  37. }
  38.  
  39.  
  40.  
  41. int main(void)
  42. {
  43.     sei(); //global enable interrupt function for external events
  44.    
  45.     DDRB |= 1;
  46.     init_timer();
  47.    
  48.     while (1)
  49.     {
  50.         if (ev == 1)
  51.         {
  52.            
  53.                 if(!x) //blink-ane corect
  54.                 {
  55.                    
  56.                     PORTB |= 1;
  57.                 }
  58.                 else
  59.                 {
  60.                     PORTB = 0;
  61.                 }
  62.                 x = x ? 0 : 1;
  63.         ev = 0;
  64.         }      
  65.         ////
  66.     }
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement