السلام عليكم ... لقد حصلت على هذا المثال للتحكم بمنفذ الطابعة .... ولكن عند استخدامه أو بالأحرى عند كتابة هذه الشيفرة تظهر الأخطاء التالية :
[Error] Unit1.pas(11): Unsatisfied forward or external declaration: 'TForm1.PortOut'
[Error] Unit1.pas(12): Unsatisfied forward or external declaration: 'TForm1.PortOutW'
[Error] Unit1.pas(13): Unsatisfied forward or external declaration: 'TForm1.PortInW'
[Error] Unit1.pas(14): Unsatisfied forward or external declaration: 'TForm1.PortIn'
[Error] Unit1.pas(15): Unsatisfied forward or external declaration: 'TForm1.FormCreate'
[Error] Unit1.pas(16): Unsatisfied forward or external declaration: 'TForm1.SetOutV'
[Error] Unit1.pas(17): Unsatisfied forward or external declaration: 'TForm1.Button1Click'
[Error] Unit1.pas(18): Unsatisfied forward or external declaration: 'TForm1.Button2Click'
[Error] Unit1.pas(19): Unsatisfied forward or external declaration: 'TForm1.ReadInput'
[Error] Unit1.pas(20): Unsatisfied forward or external declaration: 'TForm1.Button3Click'
[Fatal Error] Project1.dpr(5): Could not compile used unit 'Unit1.pas'
أرجوا منكم التصحيح ...... جزاكم الله كل خير
اقتباسusesWindows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, Math, ExtCtrls;
type
TForm1 = class(TForm)
Edit1: TEdit;
Edit2: TEdit;
Edit3: TEdit;
Edit4: TEdit;
Button1: TButton;
Button2: TButton;
Panel1: TPanel;
Panel2: TPanel;
Edit5: TEdit;
Edit6: TEdit;
Edit7: TEdit;
Edit8: TEdit;
Edit9: TEdit;
Edit10: TEdit;
Edit11: TEdit;
Edit12: TEdit;
Edit13: TEdit;
Button3: TButton;
procedure PortOut(IOport:word; Value:byte);
procedure PortOutW(IOport:word; Value:word);
function PortInW(IOport:word):word;
function PortIn(IOport:word):byte;
procedure FormCreate(Sender: TObject);
procedure SetOutV;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
function ReadInput(Chan: variant): Variant;
procedure Button3Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
A, B: integer;
implementation
{$R *.DFM}
function TForm1.PortIn(IOport:word):byte; assembler;
asm
mov dx,ax
in al,dx
end;
function TForm1.PortInW(IOport:word):word; assembler;
asm
mov dx,ax
in ax,dx
end;
procedure TForm1.PortOutW(IOport:word; Value:word); assembler;
asm
xchg ax,dx
out dx,ax
end;
procedure TForm1.PortOut(IOport:word; Value:byte); assembler;
asm
xchg ax,dx
out dx,al
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
A := 0;
B := 0;
end;
procedure TForm1.SetOutV;
var V1, V2, N: Variant;
X, Y, Z: integer;
begin
PortOut(888, 128); //Switch Power ON
V1 := Edit1.Text;
V1 := Int(V1 * 51.2);
V2 := Edit2.Text;
V2 := Int(V2 * 51.2);
//Send 8 Clock Pulses to DA Data
for X := 1 to 8 do
begin
PortOut(888, 130);
PortOut(888, 128);
end;
//Send Second 8 Clock Pulses and DAC1 Data
for X := 9 to 16 do
begin
Y := 16 - X;
Z := ((V1 and power(2,Y))/power(2,Y)) or 128;
PortOut(888, Z);
PortOut(888, Z or 2);
PortOut(888, Z);
end;
//Send Third 8 Clock Pulses and DAC0 Data
for X := 17 to 24 do
begin
Y := 16 - X;
Z := ((V1 and power(2,Y))/power(2,Y)) or 128;
PortOut(888, Z);
PortOut(888, Z or 2);
PortOut(888, Z);
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
SetOutV;
PortOut(888, $84);
PortOut(888, $80);
PortOut(890, $11);//Could be 11
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
SetOutV;
PortOut(888, $84);
PortOut(888, $80);
PortOut(890, $11);//Could be 11
end;
//Read ADC Input Voltages
function TForm1.ReadInput(Chan: Variant): Variant;
var V: Variant;
X, Y, Addr, Tst: integer;
begin
V := 0;
for Y := 1 to 2 do
begin
PortOut(888, $80);//Select Signal to IC4
V := V or (PortIn(8889) and $10) * $8;//Read Data bit 7
//Send Input Addr (MSB first) and read Output bits 6-3
for X := 1 to 4 do
begin
Addr := $80 + $40 * (Chan and power(2, (4 - X))) div power(2, (4 - X));
V := V or (PortIn(889) and $10) * (power(2, (8 - X))) / $10;
PortOut(888, Addr);
PortOut(888, Addr or $2);
PortOut(888, Addr and $FD);
end;
//Sample and Hold begins (after 4th falling edge of I/O clock)
for X := 5 to 8 do
begin
V := V or (PortIn(889) and $10) * (power(2, (8 - X))) / $10;
PortOut(888, $82);
PortOut(888, $80);
end;
//After the 8th clock, chip select must go high or the I/O clock
//must remain low for at least 20us for the donversion to be completed
PortOut(888, $A0); //Chip deselect
Tst := 0;
while Tst = 0 do Tst := PortIn(889) and $40;
if Y = 1 then V := 0;
end;
Result := V;
end;
procedure TForm1.Button3Click(Sender: TObject);
begin
PortOut(888, $A0);//Power ON and ADC in deselct mode
Edit3.Text := ReadInput(0);
Edit4.Text := ReadInput(1);
Edit5.Text := ReadInput(2);
Edit6.Text := ReadInput(3);
Edit7.Text := ReadInput(4);
Edit8.Text := ReadInput(5);
Edit9.Text := ReadInput(6);
Edit10.Text := ReadInput(7);
Edit11.Text := ReadInput(8);
Edit12.Text := ReadInput(9);
Edit13.Text := ReadInput(10);
end;
end.