Facebook
From Chunky Bison, 5 Years ago, written in C.
Embed
Download Paste or View Raw
Hits: 228
  1. /*
  2.  * GccApplication3.c
  3.  *
  4.  * Created: 08.10.2018 15:21:47
  5.  * Author : student
  6.  */
  7.  
  8. #include <avr/io.h>
  9. #include <inttypes.h>
  10. #include <avr/interrupt.h>
  11. #include <avr/sleep.h>
  12.  
  13. //-----------------------------------------------------
  14.  
  15. volatile int x;
  16.  
  17. ISR(INT0_vect)
  18. {
  19.         TCNT1=0;
  20.                 x++;
  21. }
  22.  
  23. ISR(INT1_vect)
  24. {
  25.         TIMSK=0;
  26.  
  27. }
  28.  
  29. ISR(Timer1_COMPA_vect)
  30. {
  31.         if(x<7)
  32.       x++;
  33. }
  34.  
  35. int main(void)
  36. {
  37.        
  38.                 TCCRA=0;
  39.                 TCCRB=0;
  40.                 TCNT1=0;
  41.  
  42.                 OCR1A=977;
  43.                 TIMSK = _BV(OCIE1A);
  44.                 TCCR1A= _BV(CS12) | _BV(CS10) | _BV(WGM12);
  45.  
  46.                 DDRB=0xFF;
  47.      
  48.         GICR=_BV(INT0) | _BV(INT1);
  49.         MCUCR= _BV(ISC11) | _BV(ISC01);
  50.  
  51.         sei();
  52.         x=0;
  53.  
  54.     /* Replace with your application code */
  55.     while (1)
  56.     {
  57.          sleep_mode();
  58.          PORTB=~_BV(x);
  59.     }
  60. }
  61.  
  62.