Advertisement
gabrielaozegovic

Untitled

Dec 12th, 2017
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. #define F_CPU 7372800UL
  2.  
  3. #include <avr/io.h>
  4. #include <util/delay.h>
  5. #include <avr/interrupt.h>
  6.  
  7. static uint8_t counter = 0;
  8. static uint8_t flag = 0;
  9.  
  10. void debounce(){
  11. _delay_ms(300);
  12. GIFR = _BV(INTF0) | _BV(INTF1);
  13. }
  14.  
  15. ISR(INT1_vect){
  16. PORTA = PORTA << 1;
  17. PORTA |= 0x01;
  18. debounce();
  19. }
  20.  
  21. ISR(INT0_vect){
  22. PORTA = PORTA >> 1;
  23. if(PORTA == 0x00){
  24. flag = 1;
  25. }
  26. debounce();
  27. }
  28.  
  29. void aktivnost(){
  30.  
  31. if(counter == 10){
  32. flag = 0;
  33. counter = 0;
  34. return;
  35. }
  36. if(counter < 10){
  37. PORTA = ~PORTA;
  38. counter++;
  39. }
  40.  
  41.  
  42. }
  43.  
  44. int main(void){
  45.  
  46. PORTA = 0xff;
  47. DDRA = 0xff;
  48.  
  49. MCUCR = _BV(ISC11) | _BV(ISC10) | _BV(ISC01) | _BV(ISC00);
  50. GICR = _BV(INT0) | _BV(INT1);
  51.  
  52. sei();
  53. while (1) {
  54.  
  55.  
  56. if(flag == 1){
  57. aktivnost();
  58. }
  59.  
  60. _delay_ms(300);
  61. }
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement