Advertisement
Guest User

Untitled

a guest
Nov 22nd, 2017
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1. /*
  2. * main.c
  3. *
  4. * Created on: 8 lis 2017
  5. * Author: Student
  6. */
  7. #include <avr/io.h>
  8. #include <util/delay.h>
  9.  
  10.  
  11. #define LED_PIN (0b11111111)
  12. #define LED_TOG PORTC ^= LED_PIN
  13. #define KEY_PIN (1<<PD0)
  14. #define KEY_DOWN !(PIND & KEY_PIN)
  15.  
  16. int main(void)
  17. {
  18. DDRC |= LED_PIN;
  19. PORTC |=LED_PIN;
  20. DDRD &= ~KEY_PIN;
  21. PORTD |= KEY_PIN;
  22.  
  23.  
  24. uint8_t klawisz();
  25.  
  26. while(1)
  27. {
  28. while(1)
  29. {
  30. for(int i=7;i>-1;i--)
  31. {
  32. PORTC =(1<<i);
  33. _delay_ms(100);
  34. PORTC ^=(1<<i);
  35. _delay_ms(100);
  36. }
  37. if (klawisz()) break;
  38. }
  39. while(1)
  40. {
  41. for(int i=0;i<8;i++)
  42. {
  43. PORTC =(1<<i);
  44. _delay_ms(100);
  45. PORTC ^=(1<<i);
  46. _delay_ms(100);
  47. }
  48. if (klawisz()) break;
  49. }
  50. ;
  51. }
  52. }
  53.  
  54.  
  55.  
  56. uint8_t klawisz (void)
  57. { if(KEY_DOWN){
  58. _delay_ms(80);
  59. if (KEY_DOWN) return 1;
  60. } return 1;
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement