Advertisement
Guest User

Untitled

a guest
Mar 23rd, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. #include <avr/io.h>
  2. #include <util/delay.h>
  3. // *** Primitive wait() ***
  4. void wait(uint16_t time)
  5. {
  6. volatile uint16_t i;
  7. for(i=0;i<2000;i++)
  8. _delay_loop_2(time);
  9. }
  10. int main(void)
  11. {
  12. volatile uint8_t i;
  13. DDRB = 0xFF; // suunta ulos
  14. DDRD = 0x00;
  15. PORTD = 0xff; //yl�sveto
  16. while(1)
  17. {
  18. if (~PIND & 0x01) //testataan onko alin bitti nolla
  19. {
  20. wait(10);
  21. while (~PIND & 0x01);
  22. PORTB = PORTB ^0x03;
  23. }
  24. if (~PIND & 0x02) //PIND2 painamalla syttyvät/sammuvat ledit 3 & 4
  25. {
  26. wait(10);
  27. while (~PIND & 0x02);
  28. PORTB = PORTB ^0x0C;
  29. }
  30. if (~PIND & 0x04) //PIND3 painamalla syttyvät/sammuvat ledit 5 & 6
  31. {
  32. wait(10);
  33. while (~PIND & 0x04);
  34. PORTB = PORTB ^0x30;
  35. }
  36. if (~PIND & 0x08) //PIND3 painamalla syttyvät/sammuvat ledit 7 & 8
  37. {
  38. wait(10);
  39. while (~PIND & 0x08);
  40. PORTB = PORTB ^0xC0;
  41. }
  42. if (~PIND & 0x10) //PIND4 painamalla sammuvat kaikki ledit
  43. {
  44. wait(10);
  45. while (~PIND & 0x10);
  46. PORTB = 0xff;
  47. }
  48.  
  49. if (~PIND & 0x20) //PIND5 painamalla pohjassa, vilkkuvat kaikki ledit portissa B
  50. {
  51.  
  52. wait(10);
  53. while(~PIND & 0x20){
  54.  
  55. PORTB = PORTB ^0xFF;
  56. wait(350);
  57.  
  58.  
  59. }
  60. }
  61.  
  62. }
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement