Advertisement
Guest User

Untitled

a guest
Dec 15th, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. #include <avr\io.h> // Most basic include files
  2. #include <avr\interrupt.h> // Add thenecessary ones
  3. #include <avr\signal.h> // here
  4. //#define F_CPU 11059200U
  5. #include <util\delay.h>
  6.  
  7.  
  8. #define MOVER(x) (x << 1 | x >> 7)
  9. #define MOVEL(x) (x >> 1 | x << 7)
  10.  
  11.  
  12. int main(void) {
  13. DDRE = 0xff;
  14. DDRA = 0xff;
  15. PORTE = _BV(PE3);
  16. PORTA = 1;
  17.  
  18.  
  19. uint8_t state4 = 0;
  20. uint8_t buttonState4 = 0;
  21.  
  22. uint8_t state5 = 0;
  23. uint8_t buttonState5 = 0;
  24.  
  25. uint8_t dir = 1;
  26.  
  27.  
  28. while(1) {
  29. if(((PIND & _BV(PD4)) == 0) && buttonState4 == 0){
  30. state4 = !state4;
  31. buttonState4 = 1;
  32. }
  33.  
  34.  
  35. if((PIND & _BV(PD4)) != 0)
  36. buttonState4 = 0;
  37.  
  38. if(state4) {
  39. dir = 0;
  40. state4 = 0;
  41. }
  42.  
  43.  
  44.  
  45. if(((PIND & _BV(PD5)) == 0) && buttonState5 == 0){
  46. state5 = !state5;
  47. buttonState5 = 1;
  48. }
  49.  
  50. if((PIND & _BV(PD5)) != 0)
  51. buttonState5 = 0;
  52.  
  53. if(state5) {
  54. dir = 1;
  55. state5 = 0;
  56. }
  57.  
  58. _delay_ms(100);
  59. if(dir)
  60. PORTA = MOVER(PORTA);
  61. else
  62. PORTA = MOVEL(PORTA);
  63.  
  64. }
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement