Advertisement
Einstein_R

Untitled

Jul 7th, 2014
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.71 KB | None | 0 0
  1. #include <avr/io.h>
  2. #include <util/delay.h>
  3. #include <avr/interrupt.h>
  4. #include <stdbool.h>
  5. #include <string.h>
  6.  
  7. bool debButton(const unsigned char pin[4], int x)
  8. {
  9.  
  10.     _delay_ms(20);
  11.     if(bit_is_clear(PINB, x))
  12.     {
  13.     //  if(pin == "PINB"))
  14.     //      { PORTB &= ~(1 << PINB3); }
  15.         while ((bit_is_clear(pin, x))) {}
  16.         return true;
  17.     }
  18.     else
  19.     {
  20.         return false;
  21.     }
  22. }
  23.  
  24. int main(void)
  25. {
  26.  
  27. DDRB |= 1 << PINB0;
  28. DDRB &= ~(1 << PINB2);
  29. DDRB |= 1 << PINB3;
  30. DDRB |= 1 << PINB1;
  31.  
  32. PORTB |= 1 << PINB3;
  33.  
  34.     while(1)
  35.     {
  36.         if(bit_is_clear(PINB,2))
  37.         {
  38.  
  39.             PORTB |= 1 << PINB0;
  40.             if( debButton("PINB",2))
  41.             {
  42.                 PORTB ^= 1 << PINB1;
  43.             }
  44.             else
  45.             {
  46.  
  47.             }
  48.         }
  49.         else
  50.         {
  51.             PORTB &= ~(1 << PINB0);
  52.         }
  53.     }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement