Zapojení 6
Příklad zdrojového kódu
 Tisk

Program Uloha_6;

uses crt, newdelay;

var I, DS, krokyC : integer;

    uhelA, uhelB, uhelC : real;

    smer : string[3];

    CW : boolean;



(*Funkce, která převede řetězec na velká písmena*)

function UpString(s:string):string;

var i: byte;

begin

     for i:=1 to length(s) do s[i]:=upcase(s[i]);

     UpString:=s;

end;



begin

    (*Úvodní výpis programu *)

     writeln('MAT - Pridavny modul Krokovy motor');

     writeln('Uloha 6');

     writeln('Pro spusteni stisknete <Enter>');

     readln;

     (*Počáteční nastavení proměnných *)

     DS:=9;

     uhelB:=0;

     writeln('Jste otoceni na sever');


   repeat

     (*Výpis směrů otáčení*)

     writeln('Zadejte smer kterym se chcete otocit');

     writeln;

     writeln('Sever - S');

     writeln('Jih - J');

     writeln('Vychod - V');

     writeln('Zapad - Z');

     writeln('Severovychod -SV');

     writeln('Severozapad - SZ');

     writeln('Jihovychod - JV');

     writeln('Jihozapad - JZ');

     writeln('Severseverovychod - SSV');

     writeln('Severoseverozapad - SSZ');

     writeln('Jihojihovychod - JJV');

     writeln('Jihojihozapad - JJZ');

     writeln('Vychodseverovychod - VSV');

     writeln('Vychodjihovychod - VJV');

     writeln('Zapadjihozapad - ZJZ');

     writeln('Zapadseverozapad - ZSZ');

     Writeln('--- pro ukonceni zadejte Q ---');

     readln(smer);


     smer:=UpString(smer);


     (*Zjištění úhlu*)

     if smer='S' then uhelA:=0

     else if smer='SSZ' then uhelA:=22.5

     else if smer='SZ' then uhelA:=45

     else if smer='ZSZ' then uhelA:=67.5

     else if smer='Z' then uhelA:=90

     else if smer='ZJZ' then uhelA:=112.5

     else if smer='JZ' then uhelA:=135

     else if smer='JJZ' then uhelA:=157.5

     else if smer='J' then uhelA:=180

     else if smer='JJV' then uhelA:=202.5

     else if smer='JV' then uhelA:=225

     else if smer='VJV' then uhelA:=247.5

     else if smer='V' then uhelA:=270

     else if smer='VSV' then uhelA:=292.5

     else if smer='SV' then uhelA:=315

     else if smer='SSV' then uhelA:=337.5;


     (*Zjištění směru a velikosti krokování *)

     uhelC:=uhelA-uhelB;

     uhelB:=uhelA;

     if uhelC>0 then

     begin


          if abs(uhelC)<=180 then

          begin

               CW:=true;

               uhelC:=abs(uhelC);

          end

          else

          begin

               CW:=false;

               uhelC:=360-abs(uhelC);

          end;

     end

     else

     begin

          if abs(uhelC)<=180 then

          begin

               CW:=false;

               uhelC:=abs(uhelC);

          end

          else

          begin

               CW:=true;

               uhelC:=360-abs(uhelC);

          end;

     end;

     krokyC:=trunc(uhelC/7.5);


     (*Realizace krokování *)

     for I:=1 to krokyC do

     begin

          if CW then

             begin

                  if DS=10 then DS:=6

                  else if DS=6 then DS:=5

                  else if DS=5 then DS:=9

                  else if DS=9 then DS:=10;

             end

             else

             begin

                  if DS=10 then DS:=9

                  else if DS=9 then DS:=5

                  else if DS=5 then DS:=6

                  else if DS=6 then DS:=10;

             end;


             port[$300]:=DS;

             delay(20);


          end;

until(smer='Q');

     (*Ukončení prohramu*)

     writeln('Program ukoncen ... stisknete <Enter>');

     readln;

end.