Subversion Repositories svnkaklik

Rev

Details | Last modification | View Log

Rev Author Line No. Line
6 kaklik 1
unit LPTMot;
2
 
3
interface
4
 
5
uses  PORTINC,
6
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
7
  StdCtrls, ExtCtrls;
8
 
9
type
10
  TForm1 = class(TForm)
11
    Button1: TButton;
12
    Button2: TButton;
13
    Edit1: TEdit;
14
    RadioButton1: TRadioButton;
15
    RadioButton2: TRadioButton;
16
    RadioButton3: TRadioButton;
17
    RadioButton4: TRadioButton;
18
    Button3: TButton;
19
    Button4: TButton;
20
    Label1: TLabel;
21
    Timer1: TTimer;
22
    Timer2: TTimer;
23
    Button5: TButton;
24
    Button6: TButton;
25
    Button7: TButton;
26
    Button8: TButton;
27
    Timer3: TTimer;
28
    CheckBox1_4: TCheckBox;
29
    CheckBox1_5: TCheckBox;
30
    CheckBox1_6: TCheckBox;
31
    CheckBox1_7: TCheckBox;
32
    Button9: TButton;
33
    procedure FormCreate(Sender: TObject);
34
    procedure Button1Click(Sender: TObject);
35
    procedure Button2Click(Sender: TObject);
36
    procedure Edit1Change(Sender: TObject);
37
    procedure RadioButton1Click(Sender: TObject);
38
    procedure RadioButton2Click(Sender: TObject);
39
    procedure RadioButton3Click(Sender: TObject);
40
    procedure RadioButton4Click(Sender: TObject);
41
    procedure Button3Click(Sender: TObject);
42
    procedure Button4Click(Sender: TObject);
43
    procedure Timer1Timer(Sender: TObject);
44
    procedure Button5Click(Sender: TObject);
45
    procedure Button6Click(Sender: TObject);
46
    procedure Button8Click(Sender: TObject);
47
    procedure Button7Click(Sender: TObject);
48
    procedure Timer3Timer(Sender: TObject);
49
    procedure Button9Click(Sender: TObject);
50
  end;
51
 
52
var
53
  Form1: TForm1;
54
  krok1, krok2, krok3 : Byte;
55
  msteps: integer;
56
  smer: byte;
57
const BA = $378;             { LPT1 }
58
      vpravo = true;
59
      vlevo = false;
60
  mspeed = 10;
61
 
62
 
63
implementation
64
 
65
{$R *.DFM}
66
procedure Motor1 (vpravo : Boolean);
67
begin
68
  if vpravo then begin
69
    krok1 := krok1 * 2;
70
    if krok1 = 16 then krok1 := 1
71
  end else begin
72
    krok1 := krok1 div 2;
73
    if krok1 = 0 then krok1 := 8;
74
  end;
75
  OutPort(BA, krok1 + 16 * krok2);
76
end;
77
 
78
procedure Motor2 (vpravo : Boolean);
79
begin
80
  if vpravo then begin
81
    krok2 := krok2 * 2;
82
    if krok2 = 16 then krok2 := 1
83
  end else begin
84
    krok2 := krok2 div 2;
85
    if krok2 = 0 then krok2 := 8;
86
  end;
87
  OutPort(BA, krok1 + 16 * krok2);
88
end;
89
 
90
procedure Motor3 (vpravo : Boolean);
91
begin
92
  if vpravo then begin
93
    krok3 := krok3 * 2;
94
    if krok3 = 16 then krok3 := 1
95
  end else begin
96
    krok3 := krok3 div 2;
97
    if krok3 = 0 then krok3 := 8;
98
  end;
99
  OutPort(BA+2, krok3 XOR 11);
100
end;
101
 
102
function spinac1: Boolean;
103
begin
104
  if (InPort(BA+1) and 8) = 0 then spinac1 := true   else spinac1 := false;
105
end;
106
 
107
function spinac2: Boolean;
108
begin
109
  if (InPort(BA+1) and 16) = 0 then spinac2 := true   else spinac2 := false;
110
end;
111
 
112
function spinac3: Boolean;
113
begin
114
  if (InPort(BA+1) and 32) = 0 then spinac3 := true   else spinac3 := false;
115
end;
116
 
117
procedure nulpoloha;
118
begin
119
  repeat
120
    Motor1(vlevo);
121
    delay (5);
122
  until spinac1;
123
  repeat
124
    Motor2(vlevo);
125
    delay (5);
126
  until spinac2;
127
  repeat
128
    Motor3(vlevo);
129
    delay (5);
130
  until spinac3;
131
end;
132
 
133
 
134
procedure pohyb1;
135
var N : Word;
136
begin
137
  for n:= 1 to 100 do begin   { 100 krokù }
138
    Motor1 (vpravo);
139
    Motor2 (vpravo);          { všechny motory }
140
    Motor3 (vpravo);
141
    delay (5);                { rychle }
142
  end;
143
  for n:= 1 to 100 do begin   { 100 krokù }
144
    Motor1 (vpravo);          { jen motor 1 }
145
    delay (10);               { pomalu }
146
  end;
147
  delay(1000);                { klid 1s }
148
  for n:= 1 to 100 do begin   { 100 krokù }
149
    Motor1 (vlevo);
150
    Motor2 (vlevo);           { všechny motory }
151
    Motor3 (vlevo);
152
    delay(5);                 { rychle }
153
  end;
154
  for n:= 1 to 100 do begin   { 100 krokù }
155
    Motor1 (vlevo);           { jen motor 1 }
156
    delay (10);               { pomalu }
157
  end;
158
  delay (1000);               { klid 1s }
159
end;
160
 
161
procedure TForm1.FormCreate(Sender: TObject);
162
var ble: integer;
163
begin
164
  OpenCom (Pchar('LPT1:'));
165
  krok1 := 1;
166
  krok2 := 1;
167
  krok3 := 1;
168
  OutPort (BA,0);
169
  val(Edit1.Text,msteps,ble);
170
end;
171
 
172
procedure TForm1.Button1Click(Sender: TObject);
173
begin
174
  nulpoloha;
175
end;
176
 
177
procedure TForm1.Button2Click(Sender: TObject);
178
begin
179
  pohyb1;
180
end;
181
 
182
procedure TForm1.Edit1Change(Sender: TObject);
183
var
184
 ble:integer;
185
begin
186
   val(Edit1.Text,msteps,ble);
187
end;
188
 
189
procedure TForm1.RadioButton1Click(Sender: TObject);
190
begin
191
  OutPort(BA, 1);
192
end;
193
 
194
procedure TForm1.RadioButton2Click(Sender: TObject);
195
begin
196
  OutPort(BA, 2);
197
 
198
end;
199
 
200
procedure TForm1.RadioButton3Click(Sender: TObject);
201
begin
202
  OutPort(BA, 4);
203
 
204
end;
205
 
206
procedure TForm1.RadioButton4Click(Sender: TObject);
207
begin
208
  OutPort(BA, 8);
209
 
210
end;
211
 
212
procedure TForm1.Button3Click(Sender: TObject);
213
var n:integer;
214
begin
215
 for n:=1 to msteps do
216
 begin
217
  OutPort(BA, 5);
218
  delay(mspeed);
219
  OutPort(BA, 6);
220
  delay(mspeed);
221
  OutPort(BA, 10);
222
  delay(mspeed);
223
  OutPort(BA, 9);
224
  delay(mspeed);
225
 end;
226
 OutPort(BA, 0);
227
end;
228
 
229
procedure TForm1.Button4Click(Sender: TObject);
230
var n:integer;
231
begin
232
 for n:=1 to msteps do
233
 begin
234
  OutPort(BA, 9); //1
235
  delay (mspeed);               { pomalu }
236
  OutPort(BA, 10); //8
237
  delay (mspeed);              { pomalu }
238
  OutPort(BA, 6);  //2
239
  delay (mspeed);               { pomalu }
240
  OutPort(BA, 5);  //4
241
  delay (mspeed);               { pomalu }
242
 end;
243
 OutPort(BA, 0);
244
end;
245
 
246
 
247
procedure TForm1.Timer1Timer(Sender: TObject);
248
begin
249
  if (smer and 1)=1 then
250
    Button4Click(Sender)
251
  else
252
    Button3Click(Sender);
253
  inc(smer);
254
end;
255
 
256
procedure TForm1.Button5Click(Sender: TObject);
257
begin
258
  Timer1.Enabled:=true;
259
  Timer2.Enabled:=true;
260
end;
261
 
262
procedure TForm1.Button6Click(Sender: TObject);
263
begin
264
  Timer1.Enabled:=false;
265
  Timer2.Enabled:=false;
266
end;
267
 
268
procedure TForm1.Button8Click(Sender: TObject);
269
var n:integer;
270
begin
271
 for n:=1 to msteps do
272
 begin
273
  OutPort(BA, 1); //1
274
  delay (mspeed);               { pomalu }
275
  OutPort(BA, 8); //8
276
  delay (mspeed);              { pomalu }
277
  OutPort(BA, 2);  //2
278
  delay (mspeed);               { pomalu }
279
  OutPort(BA, 4);  //4
280
  delay (mspeed);               { pomalu }
281
 end;
282
 OutPort(BA, 0);
283
end;
284
 
285
procedure TForm1.Button7Click(Sender: TObject);
286
var n:integer;
287
begin
288
 for n:=1 to msteps do
289
 begin
290
  OutPort(BA, 4); //1
291
  delay (mspeed);               { pomalu }
292
  OutPort(BA, 2); //8
293
  delay (mspeed);              { pomalu }
294
  OutPort(BA, 8);  //2
295
  delay (mspeed);               { pomalu }
296
  OutPort(BA, 1);  //4
297
  delay (mspeed);               { pomalu }
298
 end;
299
 OutPort(BA, 0);
300
end;
301
 
302
procedure TForm1.Timer3Timer(Sender: TObject);
303
var
304
  n : integer;
305
begin
306
  n := InPort(BA+1);
307
 
308
  IF $10 = n and $10 then
309
   CheckBox1_4.Checked := false else CheckBox1_4.Checked := true;
310
  IF $20 = n and $20 then
311
   CheckBox1_5.Checked := false else CheckBox1_5.Checked := true;
312
  IF $40 = n and $40 then
313
   CheckBox1_6.Checked := false else CheckBox1_6.Checked := true;
314
  IF $80 = n and $80 then
315
   CheckBox1_7.Checked := true else CheckBox1_7.Checked := false;
316
end;
317
 
318
procedure run(turns:integer; speed:integer);
319
var n:integer;
320
begin
321
  for n:=1 to turns do
322
  begin
323
    OutPort(BA, 1);
324
    delay (speed);               { pomalu }
325
    OutPort(BA, 2);
326
    delay (speed);               { pomalu }
327
    OutPort(BA, 4);
328
    delay (speed);               { pomalu }
329
  end;
330
  OutPort(BA, 0);
331
end;
332
 
333
procedure TForm1.Button9Click(Sender: TObject);
334
var n: integer;
335
begin
336
  for n:=40 downto 10 do run(2,n);
337
  run(1000,10);
338
end;
339
 
340
end.