unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, LPTIO, StdCtrls, ExtCtrls;
type
TForm1 = class(TForm)
Shape1: TShape;
Shape2: TShape;
Shape3: TShape;
Shape4: TShape;
Shape5: TShape;
Shape6: TShape;
Shape7: TShape;
Shape8: TShape;
Shape9: TShape;
Shape10: TShape;
Shape11: TShape;
Shape12: TShape;
Shape13: TShape;
Shape14: TShape;
Shape15: TShape;
Shape16: TShape;
Shape17: TShape;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Label5: TLabel;
Label6: TLabel;
Label7: TLabel;
Label8: TLabel;
Label9: TLabel;
Label10: TLabel;
Label11: TLabel;
Label12: TLabel;
Label13: TLabel;
Label14: TLabel;
Label15: TLabel;
Label16: TLabel;
Label17: TLabel;
Shape18: TShape;
Shape19: TShape;
Shape20: TShape;
Shape21: TShape;
Shape22: TShape;
Shape23: TShape;
Label19: TLabel;
Label20: TLabel;
Label21: TLabel;
Label22: TLabel;
Label23: TLabel;
Label24: TLabel;
Label25: TLabel;
Label26: TLabel;
Label27: TLabel;
Label28: TLabel;
Label29: TLabel;
Label30: TLabel;
Label31: TLabel;
Label32: TLabel;
Label33: TLabel;
Label34: TLabel;
Label35: TLabel;
Button1: TButton;
Button2: TButton;
Button3: TButton;
Button4: TButton;
Button5: TButton;
Button6: TButton;
Button7: TButton;
Button8: TButton;
Button9: TButton;
Button14: TButton;
Button16: TButton;
Button17: TButton;
Shape24: TShape;
Shape25: TShape;
Shape26: TShape;
Label18: TLabel;
Label36: TLabel;
Label37: TLabel;
ComboBox1: TComboBox;
Timer1: TTimer;
CheckBox1: TCheckBox;
CheckBox2: TCheckBox;
CheckBox3: TCheckBox;
CheckBox4: TCheckBox;
CheckBox5: TCheckBox;
CheckBox6: TCheckBox;
CheckBox7: TCheckBox;
CheckBox8: TCheckBox;
CheckBox9: TCheckBox;
CheckBox10: TCheckBox;
CheckBox11: TCheckBox;
CheckBox12: TCheckBox;
CheckBox13: TCheckBox;
CheckBox14: TCheckBox;
CheckBox15: TCheckBox;
CheckBox16: TCheckBox;
CheckBox17: TCheckBox;
Edit1: TEdit;
procedure Button1Click (Sender: TObject);
procedure Button2Click (Sender: TObject);
procedure Button3Click (Sender: TObject);
procedure Button4Click (Sender: TObject);
procedure Button5Click (Sender: TObject);
procedure Button6Click (Sender: TObject);
procedure Button7Click (Sender: TObject);
procedure Button8Click (Sender: TObject);
procedure Button9Click (Sender: TObject);
procedure Button14Click (Sender: TObject);
procedure Button16Click (Sender: TObject);
procedure Button17Click (Sender: TObject);
procedure FormCreate (Sender: TObject);
procedure FormDestroy (Sender: TObject);
procedure Timer1Timer (Sender: TObject);
private
{Private declarations}
Lpt: TLptPortConnection;
public
{Public declarations}
function GetCurrentPort: byte;
function Pin2: boolean;
function Pin3: boolean;
function Pin4: boolean;
function Pin5: boolean;
function Pin6: boolean;
function Pin7: boolean;
function Pin8: boolean;
function Pin9: boolean;
function Pin1: boolean;
function Pin14: boolean;
function Pin16: boolean;
function Pin17: boolean;
function Pin10: boolean;
function Pin11: boolean;
function Pin12: boolean;
function Pin13: boolean;
function Pin15: boolean;
procedure ButtonPin2;
procedure ButtonPin3;
procedure ButtonPin4;
procedure ButtonPin5;
procedure ButtonPin6;
procedure ButtonPin7;
procedure ButtonPin8;
procedure ButtonPin9;
procedure ButtonPin1;
procedure ButtonPin14;
procedure ButtonPin16;
procedure ButtonPin17;
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1. FormCreate (Sender: TObject);
var
msg: AnsiString;
begin
Lpt:= TLptPortConnection. Create;
if not Lpt. Ready then
begin
msg:= 'Помилка при створенні обєкта Lpt, драйвер ERROR, код = ' + Application. MessageBox (PChar(msg), 'ERROR', MB_OK);
Application. Terminate;
end;
ComboBox1. Items. Clear;
if Lpt. IsPortPresent(LPT1) then
ComboBox1. Items. Add ('$3BC');
if Lpt. IsPortPresent(LPT2) then
ComboBox1. Items. Add ('$378');
if Lpt. IsPortPresent(LPT3) then
ComboBox1. Items. Add ('$278');
if 0=ComboBox1. Items. Count then
begin
ComboBox1. Items. Add ('LPT ïîðò³â íå çíàéäåíî');
ComboBox1. ItemIndex:= 0;
end
else
ComboBox1. ItemIndex:= 0;
Lpt. WritePort (GetCurrentPort, 0,0);
Lpt. WritePort (GetCurrentPort, 2,3);
end;
procedure TForm1. FormDestroy (Sender: TObject);
begin
Lpt. Destroy;
Timer1. Enabled:= false;
end;
function TForm1. GetCurrentPort:byte;
begin
if '$3BC' = ComboBox1. Text then
GetCurrentPort:=LPT1
else
if '$378' = ComboBox1. Text then
GetCurrentPort:=LPT2
else
GetCurrentPort:=LPT3;
end;
procedure TForm1. Timer1Timer (Sender: TObject);
begin
CheckBox1. Checked:= Pin1;
CheckBox2. Checked:= Pin2;
CheckBox3. Checked:= Pin3;
CheckBox4. Checked:= Pin4;
CheckBox5. Checked:= Pin5;
CheckBox6. Checked:= Pin6;
CheckBox7. Checked:= Pin7;
CheckBox8. Checked:= Pin8;
CheckBox9. Checked:= Pin9;
CheckBox10. Checked:= Pin10;
CheckBox11. Checked:= Pin11;
CheckBox12. Checked:= Pin12;
CheckBox13. Checked:= Pin13;
CheckBox14. Checked:= Pin14;
CheckBox15. Checked:= Pin15;
CheckBox16. Checked:= Pin16;
CheckBox17. Checked:= Pin17;
if Pin1=true then
Shape1. Brush. Color:=clRed
else
Shape1. Brush. Color:=clWhite;
if Pin2=true then
Shape2. Brush. Color:=clRed
else
Shape2. Brush. Color:=clWhite;
if Pin3=true then
Shape3. Brush. Color:=clRed
else
Shape3. Brush. Color:=clWhite;
if Pin4=true then
Shape4. Brush. Color:=clRed
else
Shape4. Brush. Color:=clWhite;
if Pin5=true then
Shape5. Brush. Color:=clRed
else
Shape5. Brush. Color:=clWhite;
if Pin6=true then
Shape6. Brush. Color:=clRed
else
Shape6. Brush. Color:=clWhite;
if Pin7=true then
Shape7. Brush. Color:=clRed
else
Shape7. Brush. Color:=clWhite;
if Pin8=true then
Shape8. Brush. Color:=clRed
else
Shape8. Brush. Color:=clWhite;
if Pin9=true then
Shape9. Brush. Color:=clRed
else
Shape9. Brush. Color:=clWhite;
if Pin10=true then
Shape10. Brush. Color:=clRed
else
Shape10. Brush. Color:=clWhite;
if Pin11=true then
Shape11. Brush. Color:=clRed
else
Shape11. Brush. Color:=clWhite;
if Pin12=true then
Shape12. Brush. Color:=clRed
else
Shape12. Brush. Color:=clWhite;
if Pin13=true then
Shape13. Brush. Color:=clRed
else
Shape13. Brush. Color:=clWhite;
if Pin14=true then
Shape14. Brush. Color:=clRed
else
Shape14. Brush. Color:=clWhite;
if Pin15=true then
Shape15. Brush. Color:=clRed
else
Shape15. Brush. Color:=clWhite;
if Pin16=true then
Shape16. Brush. Color:=clRed
else
Shape16. Brush. Color:=clWhite;
if Pin17=true then
Shape17. Brush. Color:=clRed
else
Shape17. Brush. Color:=clWhite;
end;
procedure TForm1. Button1Click (Sender: TObject);
begin
ButtonPin1;
end;
procedure TForm1. Button2Click (Sender: TObject);
begin
ButtonPin2;
end;
procedure TForm1. Button3Click (Sender: TObject);
begin
ButtonPin3;
end;
procedure TForm1. Button4Click (Sender: TObject);
begin
ButtonPin4;
end;
procedure TForm1. Button5Click (Sender: TObject);
begin
ButtonPin5;
end;
procedure TForm1. Button6Click (Sender: TObject);
begin
ButtonPin6;
end;
procedure TForm1. Button7Click (Sender: TObject);
begin
ButtonPin7;
end;
procedure TForm1. Button8Click (Sender: TObject);
begin
ButtonPin8;
end;
procedure TForm1. Button9Click (Sender: TObject);
begin
ButtonPin9;
end;
procedure TForm1. Button14Click (Sender: TObject);
begin
ButtonPin14;
end;
procedure TForm1. Button16Click (Sender: TObject);
begin
ButtonPin16;
end;
procedure TForm1. Button17Click (Sender: TObject);
begin
ButtonPin17;
end;
procedure TForm1. ButtonPin2;
begin
Lpt. WritePort (GetCurrentPort, 0, (1 xor Lpt. ReadPort((GetCurrentPort), 0)));
end;
procedure TForm1. ButtonPin3;
begin
Lpt. WritePort (GetCurrentPort, 0, (2 xor Lpt. ReadPort((GetCurrentPort), 0)));
end;
procedure TForm1. ButtonPin4;
begin
Lpt. WritePort (GetCurrentPort, 0, (4 xor Lpt. ReadPort((GetCurrentPort), 0)));
end;
procedure TForm1. ButtonPin5;
begin
Lpt. WritePort (GetCurrentPort, 0, (8 xor Lpt. ReadPort((GetCurrentPort), 0)));
end;
procedure TForm1. ButtonPin6;
begin
Lpt. WritePort (GetCurrentPort, 0, (16 xor Lpt. ReadPort((GetCurrentPort), 0)));
end;
procedure TForm1. ButtonPin7;
begin
Lpt. WritePort (GetCurrentPort, 0, (32 xor Lpt. ReadPort((GetCurrentPort), 0)));
end;
procedure TForm1. ButtonPin8;
begin
Lpt. WritePort (GetCurrentPort, 0, (64 xor Lpt. ReadPort((GetCurrentPort), 0)));
end;
procedure TForm1. ButtonPin9;
begin
Lpt. WritePort (GetCurrentPort, 0, (128 xor Lpt. ReadPort((GetCurrentPort), 0)));
end;
procedure TForm1. ButtonPin1;
begin
Lpt. WritePort (GetCurrentPort, 2, (1 xor Lpt. ReadPort((GetCurrentPort), 2)));
end;
procedure TForm1. ButtonPin14;
begin
Lpt. WritePort (GetCurrentPort, 2, (2 xor Lpt. ReadPort((GetCurrentPort), 2)));
end;
procedure TForm1. ButtonPin16;
begin
Lpt. WritePort (GetCurrentPort, 2, (4 xor Lpt. ReadPort((GetCurrentPort), 2)));
end;
procedure TForm1. ButtonPin17;
begin
Lpt. WritePort (GetCurrentPort, 2, (8 xor Lpt. ReadPort((GetCurrentPort), 2)));
end;
function TForm1. Pin2: boolean;
var
d: boolean;
begin
d:= true;
d:= d and (1 = (1 and Lpt. ReadPort((GetCurrentPort), 0)));
Pin2:= d;
end;
function TForm1. Pin3: boolean;
var
d: boolean;
begin
d:= true;
d:= d and (2 = (2 and Lpt. ReadPort (GetCurrentPort, 0)));
Pin3:= d;
end;
function TForm1. Pin4: boolean;
var
d: boolean;
begin
d:= true;
d:= d and (4 = (4 and Lpt. ReadPort (GetCurrentPort, 0)));
Pin4:= d;
end;
function TForm1. Pin5: boolean;
var
d: boolean;
begin
d:= true;
d:= d and (8 = (8 and Lpt. ReadPort (GetCurrentPort, 0)));
Pin5:= d;
end;
function TForm1. Pin6: boolean;
var
d: boolean;
begin
d:= true;
d:= d and (16 = (16 and Lpt. ReadPort (GetCurrentPort, 0)));
Pin6:= d;
end;
function TForm1. Pin7: boolean;
var
d: boolean;
begin
d:= true;
d:= d and (32 = (32 and Lpt. ReadPort (GetCurrentPort, 0)));
Pin7:= d;
end;
function TForm1. Pin8: boolean;
var
d: boolean;
begin
d:= true;
d:= d and (64 = (64 and Lpt. ReadPort (GetCurrentPort, 0)));
Pin8:= d;
end;
function TForm1. Pin9: boolean;
var
d: boolean;
begin
d:= true;
d:= d and (128 = (128 and Lpt. ReadPort (GetCurrentPort, 0)));
Pin9:= d;
end;
function TForm1. Pin1: boolean;
var
d: boolean;
begin
d:= true;
d:= d xor (STROBE = (STROBE and Lpt. ReadPort (GetCurrentPort, 2)));
Pin1:= d;
end;
function TForm1. Pin14: boolean;
var
d: boolean;
begin
d:= true;
d:= d xor (AUTOFEED = (AUTOFEED and Lpt. ReadPort (GetCurrentPort, 2)));
Pin14:= d;
end;
function TForm1. Pin16: boolean;
var
d: boolean;
begin
d:= true;
d:= d and (INIT = (INIT and Lpt. ReadPort (GetCurrentPort, 2)));
Pin16:= d;
end;
function TForm1. Pin17: boolean;
var
d: boolean;
begin
d:= true;
d:= d xor (SELECTIN = (SELECTIN and Lpt. ReadPort (GetCurrentPort, 2)));
Pin17:= d;
end;
function TForm1. Pin10: boolean;
var
d: boolean;
begin
d:= true;
d:= d and (ACK = (ACK and Lpt. ReadPort (GetCurrentPort, 1)));
Pin10:= d;
end;
function TForm1. Pin11: boolean;
var
d: boolean;
begin
d:= true;
d:= d xor (BUSY = (BUSY and Lpt. ReadPort (GetCurrentPort, 1)));
Pin11:= d;
end;
function TForm1. Pin12: boolean;
var
d: boolean;
begin
d:= true;
d:= d and (PAPEREND = (PAPEREND and Lpt. ReadPort (GetCurrentPort, 1)));
Pin12:= d;
end;
function TForm1. Pin13: boolean;
var
d: boolean;
begin
d:= true;
d:= d and (SELECT = (SELECT and Lpt. ReadPort (GetCurrentPort, 1)));
Pin13:= d;
end;
function TForm1. Pin15: boolean;
var
d: boolean;
begin
d:= true;
d:= d and (ERROR = (ERROR and Lpt. ReadPort (GetCurrentPort, 1)));
Pin15:= d;
end;end.
Додаток2
Код програми написаний на мові Delphi для виводу двійкового числа 10000000 на світлодіодні індикатори лабораторного макету із періодом зміни інформації в 1 секунду.
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, LPTIO, ExtCtrls, StdCtrls, Spin;
type
TForm1 = class(TForm)
Button1: TButton;
Timer1: TTimer;
SpinEdit1: TSpinEdit;
CheckBox1: TCheckBox;
Label1: TLabel;
Label2: TLabel;
procedure FormCreate (Sender: TObject);
procedure FormDestroy (Sender: TObject);
procedure Timer1Timer (Sender: TObject);
procedure Button1Click (Sender: TObject);
procedure SpinEdit1Change (Sender: TObject);
private
{Private declarations}
Lpt: TLptPortConnection;
public
{Public declarations}
function GetCurrentPort: byte;
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1. FormCreate (Sender: TObject);
var
msg: AnsiString;
begin
Lpt:= TLptPortConnection. Create;
if not Lpt. Ready then
begin {объект не готов – покажем код ошибки}
msg:= 'Ошибка при создании объекта Lpt, драйвер ERROR, код = ' + IntToStr (GetLastError());
Application. MessageBox (PChar(msg), 'ERROR', MB_OK);
Application. Terminate;
end;
Lpt. WritePort (GetCurrentPort, 0,0);
Lpt. WritePort (GetCurrentPort, 2,3);
end;
procedure TForm1. FormDestroy (Sender: TObject);
begin
Lpt. Destroy;
Timer1. Enabled:= false;
end;
function TForm1. GetCurrentPort:byte;
begin
if Lpt. IsPortPresent(LPT1) then
GetCurrentPort:=LPT1
else
if Lpt. IsPortPresent(LPT2) then
GetCurrentPort:=LPT2
else
if Lpt. IsPortPresent(LPT3) then
GetCurrentPort:=LPT3;
end;
procedure TForm1. Timer1Timer (Sender: TObject);
begin
Lpt. WritePort (GetCurrentPort, 0, (1 xor Lpt. ReadPort((GetCurrentPort), 0)));
if CheckBox1. Checked=false then
CheckBox1. Checked:=true
else
CheckBox1. Checked:=false;
end;
procedure TForm1. Button1Click (Sender: TObject);
begin
if Timer1. Enabled=false then
begin
Timer1. Enabled:=true;
Button1. Caption:='Stop';
end
else
begin
Timer1. Enabled:=false;
Button1. Caption:='Start';
end;
end;
procedure TForm1. SpinEdit1Change (Sender: TObject);
begin
Timer1. Interval:=SpinEdit1. Value;
end;
end.