Advertisement
ivosexa

plotter

May 4th, 2016
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.61 KB | None | 0 0
  1. #define F_CPU 1000000UL
  2. #include <avr/io.h>
  3. #include <avr/interrupt.h>
  4. #include <util/delay.h>
  5. #include <math.h>
  6. #include <LCD4B.h>
  7.  
  8.  
  9. long counter = 0;
  10. int x = 0;
  11. int prevStep=1;
  12. int delayStepperY = 1000;
  13. int isStepperYBusy=0;
  14. int main(void)
  15. {
  16. DDRC = 0xFF;
  17. PORTC = 0x00;
  18.  
  19.  
  20.  
  21.  
  22. moveBackwards(150);
  23.  
  24. }
  25.  
  26. void moveForward(int steps)
  27. {
  28. if(isStepperYBusy==0)
  29. {isStepperYBusy=1;
  30. int stepsInLoop=0;
  31. for (stepsInLoop; stepsInLoop<=steps; stepsInLoop++)
  32. {
  33. switch(prevStep){
  34. case 1:
  35. {
  36. PORTC = 1 << PINC0;
  37. _delay_us(delayStepperY);
  38. prevStep = 2;
  39. stepsInLoop++;
  40.  
  41. }
  42. case 2:
  43. {
  44. PORTC = 1 << PINC1;
  45. _delay_us(delayStepperY);
  46. prevStep = 3;
  47. stepsInLoop++;
  48. }
  49. case 3:
  50. {
  51. PORTC = 1 << PINC2;
  52. _delay_us(delayStepperY);
  53. prevStep = 4;
  54. stepsInLoop++;
  55. }
  56. case 4:
  57. {
  58. PORTC = 1 << PINC3;
  59. _delay_us(delayStepperY);
  60. prevStep = 1;
  61. stepsInLoop++;
  62. }
  63.  
  64. }
  65.  
  66. }
  67. isStepperYBusy=0;
  68. }
  69. else{
  70. }
  71. }
  72.  
  73. void moveBackwards(int steps)
  74. {
  75. if(isStepperYBusy==0)
  76. {
  77. isStepperYBusy=1;
  78. int stepsInLoop=0;
  79. for (stepsInLoop; stepsInLoop<=steps; stepsInLoop++)
  80. {
  81. switch(prevStep){
  82. case 1:
  83. {
  84. PORTC = 1 << PINC1;
  85. _delay_us(delayStepperY);
  86. prevStep = 2;
  87. stepsInLoop++;
  88.  
  89. }
  90. case 2:
  91. {
  92. PORTC = 1 << PINC0;
  93. _delay_us(delayStepperY);
  94. prevStep = 3;
  95. stepsInLoop++;
  96. }
  97. case 3:
  98. {
  99. PORTC = 1 << PINC3;
  100. _delay_us(delayStepperY);
  101. prevStep = 4;
  102. stepsInLoop++;
  103. }
  104. case 4:
  105. {
  106. PORTC = 1 << PINC2;
  107. _delay_us(delayStepperY);
  108. prevStep = 1;
  109. stepsInLoop++;
  110. }
  111.  
  112. }
  113.  
  114. }
  115. isStepperYBusy=0;
  116. }
  117. else
  118. {
  119. }
  120. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement