Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ' ***********************************
- ' * (C) 2009 by BARTODS *
- ' * sterowanie silnikiem krokowym *
- ' * 4-y osie step/dir *
- ' * z wyłącznikiem czasowym *
- ' * 1/2 kroku i pełny krok *
- ' ***********************************
- $regfile = "m16def.dat"
- $crystal = 8000000
- Config Porta = &B00001111 'porta x
- Config Portb = &B00001111 'portb a
- Config Portc = &B00001111 'portc y
- Config Portd = &B00001111 'portd z
- Porta = 15
- Portb = 15
- Portc = 15
- Portd = 15
- 'wyjscia portow a=0 /a=1 b=2 /b=3 bajt '
- 'wejscia portow to 7=step 6=dir
- Dim X As Byte
- Dim Y As Byte
- Dim Z As Byte
- Dim A As Byte
- Dim Xf As Bit
- Dim Yf As Bit
- Dim Zf As Bit
- Dim Af As Bit
- Dim Xrest As Integer
- Dim Yrest As Integer
- Dim Zrest As Integer
- Dim Arest As Integer
- X = 1
- Y = 1
- Z = 1
- A = 1
- Xf = 0
- Yf = 0
- Zf = 0
- Af = 0
- Xrest = 0
- Yrest = 0
- Zrest = 0
- Arest = 0
- Dim Krok(8) As Byte
- Krok(1) = &B00001000
- Krok(2) = &B00001100
- Krok(3) = &B00000100
- Krok(4) = &B00000110
- Krok(5) = &B00000010
- Krok(6) = &B00000011
- Krok(7) = &B00000001
- Krok(8) = &B00001001
- Dim Rest As Byte
- Rest = &B00000000
- Waitms 50
- Porta = Krok(x)
- Portb = Krok(y)
- Portc = Krok(z)
- Portd = Krok(a)
- Set Porta.5
- Waitms 50
- If Pina.5 = 0 Then ' jeśli założono zworę to tryb pracy pełnokrokowej
- Gosub Krok
- End If
- Do
- If Pina.7 = 1 And Xf = 0 Then Gosub Xaxe
- If Pina.7 = 0 And Xf = 1 Then Xf = 0
- Incr Xrest
- If Xrest > 3000 Then
- Porta = Rest
- End If
- If Pinb.7 = 1 And Yf = 0 Then Gosub Yaxe
- If Pinb.7 = 0 And Yf = 1 Then Yf = 0
- Incr Yrest
- If Yrest > 3000 Then
- Portb = Rest
- End If
- If Pinc.7 = 1 And Zf = 0 Then Gosub Zaxe
- If Pinc.7 = 0 And Zf = 1 Then Zf = 0
- Incr Zrest
- If Zrest > 3000 Then
- Portc = Rest
- End If
- If Pind.7 = 1 And Af = 0 Then Gosub Aaxe
- If Pind.7 = 0 And Af = 1 Then Af = 0
- Incr Arest
- If Arest > 3000 Then
- Portd = Rest
- End If
- Loop
- Krok:
- Do
- If Pina.7 = 1 And Xf = 0 Then Gosub 1xaxe
- If Pina.7 = 0 And Xf = 1 Then Xf = 0
- Incr Xrest
- If Xrest > 3000 Then
- Porta = Rest
- End If
- If Pinb.7 = 1 And Yf = 0 Then Gosub 1yaxe
- If Pinb.7 = 0 And Yf = 1 Then Yf = 0
- Incr Yrest
- If Yrest > 3000 Then
- Portb = Rest
- End If
- If Pinc.7 = 1 And Zf = 0 Then Gosub 1zaxe
- If Pinc.7 = 0 And Zf = 1 Then Zf = 0
- Incr Zrest
- If Zrest > 3000 Then
- Portc = Rest
- End If
- If Pind.7 = 1 And Af = 0 Then Gosub 1aaxe
- If Pind.7 = 0 And Af = 1 Then Af = 0
- Incr Arest
- If Arest > 3000 Then
- Portd = Rest
- End If
- Loop
- Xaxe:
- If Pina.6 = 1 Then
- Incr X
- If X = 9 Then X = 1
- Porta = Krok(x)
- Else
- Decr X
- If X = 0 Then X = 8
- Porta = Krok(x)
- End If
- Xf = 1
- Xrest = 0
- Return
- Yaxe:
- If Pinb.6 = 1 Then
- Incr Y
- If Y = 9 Then Y = 1
- Portb = Krok(y)
- Else
- Decr Y
- If Y = 0 Then Y = 8
- Portb = Krok(y)
- End If
- Yf = 1
- Yrest = 0
- Return
- Zaxe:
- If Pinc.6 = 1 Then
- Incr Z
- If Z = 9 Then Z = 1
- Portc = Krok(z)
- Else
- Decr Z
- If Z = 0 Then Z = 8
- Portc = Krok(z)
- End If
- Zf = 1
- Zrest = 0
- Return
- Aaxe:
- If Pind.6 = 1 Then
- Incr A
- If A = 9 Then A = 1
- Portd = Krok(a)
- Else
- Decr A
- If A = 0 Then A = 8
- Portd = Krok(a)
- End If
- Af = 1
- Arest = 0
- Return
- 1xaxe:
- If Pina.6 = 1 Then
- X = X + 2
- If X = 9 Then X = 1
- Porta = Krok(x)
- Else
- X = X - 2
- If X = 255 Then X = 7
- Porta = Krok(x)
- End If
- Xf = 1
- Xrest = 0
- Return
- 1yaxe:
- If Pinb.6 = 1 Then
- Y = Y + 2
- If Y = 9 Then Y = 1
- Portb = Krok(y)
- Else
- Y = Y - 2
- If Y = 255 Then Y = 7
- Portb = Krok(y)
- End If
- Yf = 1
- Yrest = 0
- Return
- 1zaxe:
- If Pinc.6 = 1 Then
- Z = Z + 2
- If Z = 9 Then Z = 1
- Portc = Krok(z)
- Else
- Z = Z - 2
- If Z = 255 Then Z = 7
- Portc = Krok(z)
- End If
- Zf = 1
- Zrest = 0
- Return
- 1aaxe:
- If Pind.6 = 1 Then
- A = A + 2
- If A = 9 Then A = 1
- Portd = Krok(a)
- Else
- A = A - 2
- If A = 255 Then A = 7
- Portd = Krok(a)
- End If
- Af = 1
- Arest = 0
- Return
Advertisement
Add Comment
Please, Sign In to add comment