Advertisement
Guest User

Untitled

a guest
Jan 20th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. /*
  2. * Hausübung.c
  3. *
  4. * Created: 15.01.2018 17:13:44
  5. * Author : Mario
  6. */
  7.  
  8. #include <avr/io.h>
  9. #define F_CPU 16000000UL
  10. #define SETBIT(ADDRESS,BIT) (ADDRESS |= (1<<BIT))
  11. #define FLIPBIT(ADDRESS,BIT) (ADDRESS ^= (1<<BIT))
  12. #define CLEARBIT(ADDRESS,BIT) (ADDRESS &= ~(1<<BIT))
  13. #define READ(x,y) ((0u == (x & (1<<y)))?0u:1u)
  14. #include <util/delay.h>
  15.  
  16. int main(void)
  17. {
  18. DDRC = 0b1111110; // Pin0 auf Eingang schalten, die anderen sind Ausgänge
  19. PINC = 0b000001;
  20.  
  21. int i = 0; // Variable i deklarieren
  22.  
  23. while (1)
  24. {
  25. if ((PINC & (1<<PINC0))) //abfrage ob pin o gedrückt - wenn nicht - gleich weiter zu nächsten Pin
  26. {
  27. _delay_ms(200); //wenn gedrückt 100 ms warten
  28. if (PINC & (1 << PINC0))
  29. {
  30. if (i == 0)
  31. {
  32. CLEARBIT(PORTC, PORTC3);
  33. SETBIT(PORTC, PORTC1);
  34. _delay_us(500);
  35. i++;
  36. }
  37. else if (i == 1)
  38. {
  39. CLEARBIT(PORTC, PORTC1);
  40. SETBIT(PORTC, PORTC2);
  41. i++;
  42. }
  43. else if (i == 2)
  44. {
  45. CLEARBIT(PORTC, PORTC2);
  46. SETBIT(PORTC, PORTC3);
  47. i = 0;
  48. }
  49. }
  50. }
  51. }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement