Автоматический фазометр

курсовая работа

7. Программа для ПК

uses crt;

var i,k,z,contr,l,ms:Byte;

Base : word ;

Value : byte;

t :Boolean;

fase,freaquency:integer;

fase_r,freaquency_r,divider:real;

data:array[1..100,1..2]of real absolute $6B00:$0000;

Procedure OpenCom(Base:word ; Baudrate:word ; Config :byte);

begin

while Port[Base+5] and $60 <> $60 do;

Port[Base+3] := $80;

Port[Base+1] := BaudRate shr 8;

Port[Base+0] := BaudRate and $FF;

Port[Base+3] := Config;

Port[Base+4] := 0;

Port[Base+1] := 0;

end;

Procedure send_char(Base : word ; Value : byte);

begin

while ((Port[Base+5] and $20) = 0) do ;

Port[Base] := Byte(Value);

end;

Function get_char( Base : word ) : Boolean;

var status : word;

begin

Status := Port[Base + 5];

if ((Status and $1E) <> 0) or ((Status and 1) = 0 ) then get_char := False

else

begin

Value := Port[Base];

contr:=contr+Value;

get_char := True;

end;

end;

begin

z:=1;

while(z=1) do

begin

clrscr;

contr:=0;

writeln(Progam measure of fase);

writeln;

writeln(Input count measures);

Readln(i);

writeln;

writeln(Input time of measurements);

Readln(l);

Base:=MemW[$40:2]; {COM2}

OpenCom(Base,24,3 + 0 + 0); {4800,8-bit,1 stop-bit,no control error}

send_char(Base , 0); {start}

if(get_char(BASE)=TRUE) then k:=Value; {meassage about working of device}

k:=k and 1;

if(k=0) then

begin

send_char(Base , i); {number of measurements}

send_char(Base , l); {time of measurement}

for k:=1 to i do

begin

if(get_char(BASE)=TRUE) then k:=Value; {higer byte of freaquency}

freaquency:=k*256;

if(get_char(BASE)=TRUE) then k:=Value; {lower byte of freaquency}

freaquency:=freaquency+k;

freaquency_r:=10e5/freaquency; {convertion in Hz}

if(get_char(BASE)=TRUE) then k:=Value; {higer byte of fase}

fase:=k*256;

if(get_char(BASE)=TRUE) then k:=Value; {lower byte of fase}

fase:=fase+k;

if(freaquency<7) then {60MHz}

begin

divider:=1;

end;

if(freaquency>6)and(freaquency<$0E00) then {60/Nd+2}

begin

divider:=(75*freaquency)/512+1;

end;

if(freaquency>$0DFF)and(freaquency<$1C00) then {30/Nd+2}

begin

divider:=(75*freaquency)/1024+2;

end;

if(freaquency>$1BFF)and(freaquency<$3700) then {15/Nd+2}

begin

divider:=(75*freaquency)/2048+2;

end;

if(freaquency<$3700) then fase_r:=360*(freaquency_r*divider/6e7) {convertion}

else {fase measured MK}

begin

fase_r:=360*((2*fase)/freaquency);

end;

data[k][1]:=freaquency_r;

data[k][2]:=fase_r;

end;

if(get_char(BASE)=TRUE) then

begin

if(Value<>contr) then {control}

begin

z:=0;

writeln(Error COM port);

end

else

begin

l:=0;

while l=0 do

begin

clrscr;

writeln(Input number of measurements);

Readln(ms);

if(ms>100) then l:=1

else writeln(f=,data[ms,1], fase=,data[ms,2]);

ReadKey;

end;

freaquency_r:=0;

fase_r:=0;

for k:=1 to i do {medium measurements}

begin

freaquency_r:=freaquency_r+data[k,1];

fase_r:=fase_r+data[k,2];

end;

freaquency_r:=freaquency_r/i;

fase_r:=fase_r/i;

Writeln(Medium f=,freaquency_r, fase=,fase_r, o);

end;

end;

end

else

begin

clrscr;

writeln(Error COM port);

z:=0;

end;

end;

end.

Делись добром ;)