Advertisement
Guest User

moved interrupt routine to main loop

a guest
Jun 15th, 2014
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.85 KB | None | 0 0
  1. #include <avr/io.h>
  2. #include <avr/interrupt.h>
  3. #include <util/delay.h>
  4.  
  5. int extratime=0;
  6. int num_presses=0;
  7.  
  8. int main(void)
  9. {
  10.   DDRD = 0b11111111;
  11.   PORTD = 0b00000000;
  12.   DDRB = 0b11110000;
  13.   PORTB = 0b00000000;
  14.   char button_state;  
  15.  
  16.   TCCR1B |= (1 << CS12) | (1 << CS10);
  17.  
  18.   while(1)
  19.   {
  20.     if (bit_is_clear(PINB, 0)) //button is pressed
  21.     {    
  22.       if (button_state==0) //was previously not pressed)
  23.       {
  24.         num_presses++;
  25.       }
  26.       button_state=1;
  27.     }
  28.     else
  29.     {
  30.       if (button_state==1) //was previously pressed
  31.       {
  32.  
  33.       }
  34.       button_state=0;
  35.     }
  36.  
  37.     if (TCNT1 >= 15625)
  38.     {
  39.          if (extra_time == 5)
  40.          {
  41.          PORTD = num_presses;
  42.              extra_time = 0;
  43.          }
  44.          else
  45.          {
  46.              ++extra_time;
  47.          }
  48.          TCNT1 = 0;
  49.     }
  50.   }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement