Guest User

Untitled

a guest
Apr 9th, 2014
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.23 KB | None | 0 0
  1.  
  2. ' ***********************************
  3. ' * (C) 2009 by BARTODS *
  4. ' * sterowanie silnikiem krokowym *
  5. ' * 4-y osie step/dir *
  6. ' * z wyłącznikiem czasowym *
  7. ' * 1/2 kroku i pełny krok *
  8. ' ***********************************
  9.  
  10. $regfile = "m16def.dat"
  11. $crystal = 8000000
  12.  
  13. Config Porta = &B00001111 'porta x
  14. Config Portb = &B00001111 'portb a
  15. Config Portc = &B00001111 'portc y
  16. Config Portd = &B00001111 'portd z
  17.  
  18.  
  19. Porta = 15
  20. Portb = 15
  21. Portc = 15
  22. Portd = 15
  23.  
  24. 'wyjscia portow a=0 /a=1 b=2 /b=3 bajt '
  25. 'wejscia portow to 7=step 6=dir
  26.  
  27. Dim X As Byte
  28. Dim Y As Byte
  29. Dim Z As Byte
  30. Dim A As Byte
  31. Dim Xf As Bit
  32. Dim Yf As Bit
  33. Dim Zf As Bit
  34. Dim Af As Bit
  35. Dim Xrest As Integer
  36. Dim Yrest As Integer
  37. Dim Zrest As Integer
  38. Dim Arest As Integer
  39. X = 1
  40. Y = 1
  41. Z = 1
  42. A = 1
  43. Xf = 0
  44. Yf = 0
  45. Zf = 0
  46. Af = 0
  47. Xrest = 0
  48. Yrest = 0
  49. Zrest = 0
  50. Arest = 0
  51.  
  52. Dim Krok(8) As Byte
  53. Krok(1) = &B00001000
  54. Krok(2) = &B00001100
  55. Krok(3) = &B00000100
  56. Krok(4) = &B00000110
  57. Krok(5) = &B00000010
  58. Krok(6) = &B00000011
  59. Krok(7) = &B00000001
  60. Krok(8) = &B00001001
  61.  
  62. Dim Rest As Byte
  63. Rest = &B00000000
  64.  
  65. Waitms 50
  66.  
  67. Porta = Krok(x)
  68. Portb = Krok(y)
  69. Portc = Krok(z)
  70. Portd = Krok(a)
  71.  
  72. Set Porta.5
  73.  
  74. Waitms 50
  75.  
  76. If Pina.5 = 0 Then ' jeśli założono zworę to tryb pracy pełnokrokowej
  77. Gosub Krok
  78. End If
  79.  
  80.  
  81. Do
  82.  
  83. If Pina.7 = 1 And Xf = 0 Then Gosub Xaxe
  84. If Pina.7 = 0 And Xf = 1 Then Xf = 0
  85. Incr Xrest
  86. If Xrest > 3000 Then
  87. Porta = Rest
  88. End If
  89.  
  90. If Pinb.7 = 1 And Yf = 0 Then Gosub Yaxe
  91. If Pinb.7 = 0 And Yf = 1 Then Yf = 0
  92. Incr Yrest
  93. If Yrest > 3000 Then
  94. Portb = Rest
  95. End If
  96.  
  97. If Pinc.7 = 1 And Zf = 0 Then Gosub Zaxe
  98. If Pinc.7 = 0 And Zf = 1 Then Zf = 0
  99. Incr Zrest
  100. If Zrest > 3000 Then
  101. Portc = Rest
  102. End If
  103.  
  104. If Pind.7 = 1 And Af = 0 Then Gosub Aaxe
  105. If Pind.7 = 0 And Af = 1 Then Af = 0
  106. Incr Arest
  107. If Arest > 3000 Then
  108. Portd = Rest
  109. End If
  110.  
  111. Loop
  112.  
  113. Krok:
  114. Do
  115.  
  116. If Pina.7 = 1 And Xf = 0 Then Gosub 1xaxe
  117. If Pina.7 = 0 And Xf = 1 Then Xf = 0
  118. Incr Xrest
  119. If Xrest > 3000 Then
  120. Porta = Rest
  121. End If
  122.  
  123. If Pinb.7 = 1 And Yf = 0 Then Gosub 1yaxe
  124. If Pinb.7 = 0 And Yf = 1 Then Yf = 0
  125. Incr Yrest
  126. If Yrest > 3000 Then
  127. Portb = Rest
  128. End If
  129.  
  130. If Pinc.7 = 1 And Zf = 0 Then Gosub 1zaxe
  131. If Pinc.7 = 0 And Zf = 1 Then Zf = 0
  132. Incr Zrest
  133. If Zrest > 3000 Then
  134. Portc = Rest
  135. End If
  136.  
  137. If Pind.7 = 1 And Af = 0 Then Gosub 1aaxe
  138. If Pind.7 = 0 And Af = 1 Then Af = 0
  139. Incr Arest
  140. If Arest > 3000 Then
  141. Portd = Rest
  142. End If
  143.  
  144. Loop
  145.  
  146.  
  147. Xaxe:
  148. If Pina.6 = 1 Then
  149. Incr X
  150. If X = 9 Then X = 1
  151. Porta = Krok(x)
  152. Else
  153. Decr X
  154. If X = 0 Then X = 8
  155. Porta = Krok(x)
  156. End If
  157. Xf = 1
  158. Xrest = 0
  159. Return
  160.  
  161. Yaxe:
  162. If Pinb.6 = 1 Then
  163. Incr Y
  164. If Y = 9 Then Y = 1
  165. Portb = Krok(y)
  166. Else
  167. Decr Y
  168. If Y = 0 Then Y = 8
  169. Portb = Krok(y)
  170. End If
  171. Yf = 1
  172. Yrest = 0
  173. Return
  174.  
  175. Zaxe:
  176. If Pinc.6 = 1 Then
  177. Incr Z
  178. If Z = 9 Then Z = 1
  179. Portc = Krok(z)
  180. Else
  181. Decr Z
  182. If Z = 0 Then Z = 8
  183. Portc = Krok(z)
  184. End If
  185. Zf = 1
  186. Zrest = 0
  187. Return
  188.  
  189. Aaxe:
  190. If Pind.6 = 1 Then
  191. Incr A
  192. If A = 9 Then A = 1
  193. Portd = Krok(a)
  194. Else
  195. Decr A
  196. If A = 0 Then A = 8
  197. Portd = Krok(a)
  198. End If
  199. Af = 1
  200. Arest = 0
  201. Return
  202.  
  203.  
  204. 1xaxe:
  205. If Pina.6 = 1 Then
  206. X = X + 2
  207. If X = 9 Then X = 1
  208. Porta = Krok(x)
  209. Else
  210. X = X - 2
  211. If X = 255 Then X = 7
  212. Porta = Krok(x)
  213. End If
  214. Xf = 1
  215. Xrest = 0
  216. Return
  217.  
  218. 1yaxe:
  219. If Pinb.6 = 1 Then
  220. Y = Y + 2
  221. If Y = 9 Then Y = 1
  222. Portb = Krok(y)
  223. Else
  224. Y = Y - 2
  225. If Y = 255 Then Y = 7
  226. Portb = Krok(y)
  227. End If
  228. Yf = 1
  229. Yrest = 0
  230. Return
  231.  
  232. 1zaxe:
  233. If Pinc.6 = 1 Then
  234. Z = Z + 2
  235. If Z = 9 Then Z = 1
  236. Portc = Krok(z)
  237. Else
  238. Z = Z - 2
  239. If Z = 255 Then Z = 7
  240. Portc = Krok(z)
  241. End If
  242. Zf = 1
  243. Zrest = 0
  244. Return
  245.  
  246. 1aaxe:
  247. If Pind.6 = 1 Then
  248. A = A + 2
  249. If A = 9 Then A = 1
  250. Portd = Krok(a)
  251. Else
  252. A = A - 2
  253. If A = 255 Then A = 7
  254. Portd = Krok(a)
  255. End If
  256. Af = 1
  257. Arest = 0
  258. Return
Advertisement
Add Comment
Please, Sign In to add comment