You are on page 1of 8

unit Unit1;

interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, TeEngine, Series, ExtCtrls, TeeProcs, Chart, Buttons, StdCtrls,
Mask,Math;
type
TForm1 = class(TForm)
BitBtn1: TBitBtn;
TimeDiagram: TSpeedButton;
Chart2: TChart;
LineSeries1: TLineSeries;
Chart1: TChart;
LineSeries2: TLineSeries;
LineSeries3: TLineSeries;
Chart4: TChart;
LineSeries4: TLineSeries;
Chart6: TChart;
LineSeries5: TLineSeries;
Chart8: TChart;
LineSeries6: TLineSeries;
Chart5: TChart;
LineSeries7: TLineSeries;
Chart7: TChart;
LineSeries8: TLineSeries;
Chart9: TChart;
LineSeries9: TLineSeries;
Chart10: TChart;
LineSeries10: TLineSeries;
StaticText1: TStaticText;
pausebutton: TSpeedButton;
Chart3: TChart;
A: TButton;
InputA: TMaskEdit;
InputB: TMaskEdit;
B: TButton;
C: TButton;
D: TButton;
E: TButton;
F: TButton;
G: TButton;
InputC: TMaskEdit;
InputD: TMaskEdit;
InputE: TMaskEdit;
InputF: TMaskEdit;
InputG: TMaskEdit;
XNOR7IN: TButton;

OutY: TMaskEdit;
StaticText2: TStaticText;
Chart11: TChart;
Series1: TLineSeries;
JumlahError: TMaskEdit;
BanyakError: TStaticText;

//

procedure wClick(Sender: TObject);


procedure TimeDiagramClick(Sender: TObject);
procedure delay(lama:real);
procedure pause;
procedure pausebuttonClick(Sender: TObject);
procedure AClick(Sender: TObject);
procedure BClick(Sender: TObject);
procedure FClick(Sender: TObject);
procedure CClick(Sender: TObject);
procedure DClick(Sender: TObject);
procedure EClick(Sender: TObject);
procedure GClick(Sender: TObject);
procedure XNOR7INClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;
//input
inA : array[1..256] of integer = (0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0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,0,1,1,0,0,0,0,
1,1,0,0,1,1,1,1,0,0,1,1,0,0,0,0,1,1,1,1,0,0,0,0,1,1,0,0,1,1,1,1,0,0);
clk : array[1..256] of integer = (0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,
0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,
0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,
0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,
0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,
0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,
0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1);
out_y : array [1..256] of integer;
error : array [1..256] of integer;

//output

th2 : integer = 2;
th3 : integer = 3;
th6 : integer = 6;
th0 : integer = 0;
w_in : integer = 2;
c_in : integer = -1;
jb : integer = 0;
tambah : integer;
pausestat : integer;
je : integer = 0;
inpA,inpB,inpC,inpD,inpE,inpF,inpG : integer;
N1,N2,N3,nd1,nd2,nd3,nd4,nd5,nd6,
nd7,nd8,nd9,nd10,nd11,or1,or2,or3,X1,
X2,X3,X4,X5,X6,X7,X8,X9,X10,XNOR : integer; //variabel untuk penghitungan
implementation
{$R *.dfm}

procedure TFORM1.delay(lama:real); //prosedur delay untuk grafik


var ref:longint;
begin
ref:=gettickcount;
repeat application.processmessages;
until ((gettickcount-ref)>=lama);
end;
procedure TForm1.pause;
begin
repeat
application.processmessages;
until pausebutton.caption='Pause';
end;

procedure hitung;
begin
nd1:= X1*c_in + X2*c_in
if nd1<th2
then nd1:=0
else nd1:=1;
nd2:= X1*c_in + X2*w_in
if nd2<th2
then nd2:=0
else nd2:=1;
nd3:= X1*w_in + X2*c_in
if nd3<th2
then nd3:=0
else nd3:=1;
nd4:= X1*w_in + X2*w_in
if nd4<th6
then nd4:=0
else nd4:=1;

+ X3*w_in;

//mencari /A+/B+C

+ X3*c_in;

//mencari /A+B+/C

+ X3*c_in;

//mencari A+/B+/C

+ X3*w_in;

//mencari A+B+C

or1:= nd1*w_in + nd2*w_in + nd3*w_in + nd4*w_in; //mencari nd1 + nd2 + nd3


+ nd4
if or1<th2
then or1:=0
else or1:=1;
end;
procedure hitung2;
begin
nd5:= X4*c_in + X5*c_in
if nd5<th2
then nd5:=0
else nd5:=1;
nd6:= X4*c_in + X5*w_in
if nd6<th2
then nd6:=0
else nd6:=1;
nd7:= X4*w_in + X5*c_in
if nd7<th2
then nd7:=0
else nd7:=1;
nd8:= X4*w_in + X5*w_in

+ X6*w_in;

//mencari /D+/E+F

+ X6*c_in;

//mencari /D+E+/F

+ X6*c_in;

//mencari D+/E+/F

+ X6*w_in;

//mencari D+E+F

if nd8<th6
then nd8:=0
else nd8:=1;
or2:= nd5*w_in + nd6*w_in + nd7*w_in + nd8*w_in; //mencari nd5 + nd6 + nd7
+ nd8
if or2<th2
then or2:=0
else or2:=1;
end;
procedure hitung3;
begin
nd9:= X8*w_in + X9*c_in;
if nd9<th2
then nd9:=0
else nd9:=1;
nd10:= X8*c_in + X9*w_in;
if nd10<th2
then nd10:=0
else nd10:=1;
or3:= nd9*w_in + nd10*w_in;
if or3<th2
then or3:=0
else or3:=1;
end;
procedure hitung4;
begin
nd11:= X10*-1;
if nd11<th0
then nd11:=0
else nd11:=1;
end;
procedure TForm1.TimeDiagramClick(Sender: TObject);
var i:integer;
begin
if TimeDiagram.Caption='START' then TimeDiagram.Caption:='STOP'
else
if TimeDiagram.Caption='STOP' then TimeDiagram.Caption:='START';
repeat
for i:=1 to 256 do
begin
X1:=InA[i]; X2:=InB[i]; X3:=InC[i];
hitung;
X4:=InD[i]; X5:=InE[i]; X6:=InF[i];
hitung2;
X8:=or1; X9:=or2;
hitung3;
X8:=or3; X9:=InG[i];
hitung3;
X10:=or3;
hitung4;
XNOR:= nd11;

out_y[i]:=XNOR;
error[i] := ouX[i]-out_y[i];

end;
//out_y[1]:=out_y[256];
series1.Clear;
lineseries1.Clear;
lineseries2.Clear;
lineseries3.Clear;
lineseries4.Clear;
lineseries5.Clear;
lineseries6.Clear;
lineseries7.Clear;
lineseries8.Clear;
lineseries9.Clear;
lineseries10.Clear;
for i:=1 to 256 do
begin

if error[i]<>0
then je := je+1;
JumlahError.Text := inttostr(je);
lineseries10.AddXY(i,clk[i]);;
series1.AddXY(i,Error[i]);
lineseries1.AddXY(i,InA[i]);
lineseries2.AddXY(i,InB[i]);
lineseries3.AddXY(i,InC[i]);
lineseries4.AddXY(i,InD[i]);
lineseries5.AddXY(i,InE[i]);
lineseries6.AddXY(i,InF[i]);
lineseries7.AddXY(i,InG[i]);
lineseries8.AddXY(i,out_y[i+1]);
lineseries9.AddXY(i,out_y[i]);
delay (2);

end;

until TimeDiagram.Caption='START'
end;
procedure TForm1.pausebuttonClick(Sender: TObject);
begin

if pausebutton.Caption='Pause' then
begin
pausebutton.Caption:='Continue'; pause;
end;
if pausebutton.Caption='Continue' then pausebutton.Caption:='Pause';
end;
procedure TForm1.AClick(Sender: TObject);
begin
inpA := inpA + 1; if inpA >= 2 then inpA:=0;
InputA.Text := inttostr(inpA);
end;
procedure TForm1.BClick(Sender: TObject);
begin
inpB := inpB + 1; if inpB >= 2 then inpB:=0;
InputB.Text := inttostr(inpB);
end;
procedure TForm1.FClick(Sender: TObject);
begin
inpF := inpF + 1; if inpF >= 2 then inpF:=0;
InputF.Text := inttostr(inpF);
end;
procedure TForm1.CClick(Sender: TObject);
begin
inpC := inpC + 1; if inpC >= 2 then inpC:=0;
InputC.Text := inttostr(inpC);
end;
procedure TForm1.DClick(Sender: TObject);
begin
inpD := inpD + 1; if inpD >= 2 then inpD:=0;
InputD.Text := inttostr(inpD);
end;
procedure TForm1.EClick(Sender: TObject);
begin
inpE := inpE + 1; if inpE >= 2 then inpE:=0;
InputE.Text := inttostr(inpE);
end;
procedure TForm1.GClick(Sender: TObject);
begin
inpG := inpG + 1; if inpG >= 2 then inpG:=0;
InputG.Text := inttostr(inpG);
end;
procedure TForm1.XNOR7INClick(Sender: TObject);
begin
begin
X1:=InpA; X2:=InpB; X3:=InpC;
hitung;
X4:=InpD; X5:=InpE; X6:=InpF;
hitung2;
X8:=or1; X9:=or2;

hitung3;
X8:=or3; X9:=InpG;
hitung3;
X10:=or3;
hitung4;
XNOR:= nd11;
OutY.Text := inttostr(XNOR)
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
end;
end.