Witam!!
poszukuję schematu i programu do sterowania silnikami krokowymi.
znalazłem program który chciałbym wykorzystać ale gdzieś chyba jest błąd.
Ja mam swoje lata i usiłuje nauczyć się baskoma ale mam problemy.
$regfile = "M8def.dat"
$crystal = 4000000
Config Lcd = 16 * 2
Config Lcdpin = Pin , Db4 = Portb.4 , Db5 = Portb.5 , Db6 = Portb.6 , Db7 = Portb.7 , E = Portb.1 , Rs = Portb.3
Config Portc.0 = Output
Config Portc.1 = Output
Config Portc.2 = Output
Config Portc.3 = Output
'Config Portb.2 = Output
'Config Portb.0 = Output
'config portd.0=RXD
'config portd.1=TXD
Config Portd.2 = Input 'przycisk OK
Config Portd.3 = Input 'przycisk PRAWO
Config Portd.4 = Input 'przycisk GORA
'Config Portd.5 = Input 'wejscie wolne
'Config Portd.6 = Input 'przycisk DOL
'Config Portd.7 = Input 'przycisk LEWO
'Config Portc.4 = Input 'wejscie SDA onewire
'Config Portc.5 = Input 'wejscie SCL
'Config 1wire = Portc.5
'Portd.2 = 1
'Portd.3 = 1
'Portd.4 = 1
'Portd.6 = 1
'Portd.7 = 1
'Portb.0 = 1
'Dim X As Bit
'$sim
'Config Lcd = 16 * 1a
'Cursor Off
Declare Sub Mainprogram
Declare Sub Foursteps
Declare Sub Ddelay
Dim R As Word
Dim 4steps As Byte
Dim Rotations As Word
Dim X As Byte
S1 Alias Portd.2
S2 Alias Portd.3
S3 Alias Portd.4
Rotations = 100
4steps = 25
Reset Portc.0 : Reset Portc.1 : Reset Portc.2 : Reset Portc.3
Sub Mainprogram
Cls
Lcd "Turns: " ; Rotations
Do
Debounce S1 , 0 , Decrturns , Sub
Debounce S2 , 0 , Incrturns , Sub
Debounce S3 , 0 , Go_on Sub
Loop
End Sub
Decrturns:
Decr Rotations
If Rotations = 0 Then
Rotations = 1
End If
Locate 1 , 8
Lcd " "
Locate 1 , 8
Lcd Rotations
Waitms 50
Return
Incrturns:
Incr Rotations
If Rotations = 65536 Then
Rotations = 65535
End If
Locate 1 , 8
Lcd " "
Locate 1 , 8
Lcd Rotations
Waitms 50
Return
'Go_on:
'Cls
'Lcd "Waiting..."
'Wait 3
'Cls
'Lcd "Working..."
'For R = 1 To Rotations
'For X = 1 To 4steps
'Call Foursteps
'Next X
'Locate 2 , 4
'Lcd R
'Next R
'Reset Portc.0 : Reset Portc.1 : Reset Portc.2 : Reset Portc.3
'Cls
'Call Mainprogram
'Return
Sub Ddelay
Waitms 10
End Sub
Sub Foursteps
Set Portc.0 : Reset Portc.1 : Reset Portc.2 : Reset Portc.3
Call Ddelay
Reset Portc.0 : Set Portc.1 : Reset Portc.2 : Reset Portc.3
Call Ddelay
Reset Portc.0 : Reset Portc.1 : Set Portc.2 : Reset Portc.3
Call Ddelay
Reset Portc.0 : Reset Portc.1 : Reset Portc.2 : Set Portc.3
Call Ddelay
End Sub
To jest kod do sterowania
To jest kod do sterowania silnikiem unipolarnym.To program tylko testowy i nie pamiętam ,czy czegoś na koniec nie pozmieniałem.Chyba jest ok Podłączałem przez układ ul2003.