Facebook
From JA, 5 Years ago, written in C++.
Embed
Download Paste or View Raw
Hits: 260
  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.         if(x>0)
  20.         {
  21.                 x--;
  22.         }
  23.         else if(x==0)
  24.         {
  25.                 x=0;
  26.         }
  27. }
  28.  
  29. ISR(INT1_vect)
  30. {
  31.         if(x<7)
  32.         {
  33.                 x++;
  34.         }
  35.         else if(x==7)
  36.         {
  37.                 x=7;
  38.         }
  39.  
  40. }
  41.  
  42.  
  43. int main(void)
  44. {
  45.         DDRB=0xFF;
  46.         PORTB= ~_BV(x); //swieci sie
  47.  
  48.        
  49.         GICR=_BV(INT0) | _BV(INT1);
  50.         MCUCR= _BV(ISC11) | _BV(ISC01);
  51.  
  52.         sei();
  53.         x=0;
  54.  
  55.     /* Replace with your application code */
  56.     while (1)
  57.     {
  58.                 sleep_mode();
  59.                 PORTB=~_BV(x);
  60.     }
  61. }
  62.  
  63.