siagi2.docx

(14 KB) Pobierz

-- Klawiatura.adb

 

with Ada.Text_Io;               use Ada.Text_Io;

with Ada.Interrupts;            use Ada.Interrupts;

--with Ada_Interrupts_Names;      use Ada_Interrupts_Names;

with nt_console;                use nt_console;

 

procedure Klawiatura is

Zn: Character;

 

   protected Obsluga is

--      procedure Steruj;

      --pragma Attach_Handler(Steruj, 1);

      entry Nacisniety(Znak: Character);     

      private

      Warunekb: Boolean := True;

   end Obsluga;

  

   protected body Obsluga is

  --    procedure Steruj is

   --   begin

    --     null;

     -- end Steruj;

     

      entry Nacisniety(Znak: Character) when Warunekb is

      begin       

         Goto_Xy(25,4);        

         Put("" & Znak); --delay 1.0;

      end Nacisniety;      

   end Obsluga;

 

begin

   Goto_Xy(5,4);

   Put_Line(" Nacisnij klawisz : ");

   loop

      Get_Immediate(Zn);

      if Zn = 'k' then exit; end if;

      if Zn = '0' or Zn = '1' or Zn = '2' or Zn = '3' or Zn = '4' or Zn = '5' or Zn = '6' or Zn = '7' or Zn = '8' or Zn = '9' or Zn = '*' or Zn = '#' then

      Obsluga.Nacisniety(Zn); end if;

   end loop;

end Klawiatura;

   -- Zegar.adb

 

with Ada.Text_Io;         use Ada.Text_Io;

with Ada.Calendar;        use Ada.Calendar;

with nt_console;          use nt_console;

 

procedure Zegar is

   type Min is mod 60;

   type Godz is mod 24;

   Godzina: Time;  

   Przerwa: Duration := 1.0;

   G: Godz := 12;

   M: Min := 0;

   Koniec: Boolean := False;  

 

   task Sterowanie is

      entry Start;

   end Sterowanie;

  

   task body Sterowanie is

   Zn: Character;

   begin

      accept Start;

      loop

         Get_Immediate(Zn);

         if Zn = 'g' then G := G + 1;

         elsif Zn = 'm' and M = 59 then M := M + 1; G := G + 1;

         elsif Zn = 'm' then M := M + 1;

         elsif Zn = 'k' then Koniec := True; exit;

         end if;

         Goto_Xy(5,5);

         Put_Line("" & G'Img & " : " & M'Img & "  "); 

      end loop;

   end Sterowanie;

 

begin

   Sterowanie.Start;

   Godzina := Ada.Calendar.Clock;

   while not Koniec loop

      Goto_Xy(5,5);

      Put_Line("" & G'Img & " : " & M'Img & "  ");

      if M = 59 then M := M + 1; G := G + 1;

      else M := M + 1;

      end if;

      Godzina := Godzina + Przerwa;

      delay until Godzina;

   end loop;

end Zegar;

 

--generator fali:

with ada.real_time;

use ada.real_time;

 

type Bit is (0,1);

--lepiej ponoć byłoby integer range (0..1);

task generator;

 

task body generator is

    Pin_start:bit; --sygnał start (tylko do odczytu!!)

    Pin_gen:bit:=0; --wyjscie generatora, tylko do zapisu

    czas:time;

begin

loop                    --petla nieskończona, aby nie wychodzić z programu

    if pin_start=1 then

        czas:=clock;            --ustaw zegar

        while pin_start=1 loop

            pin_gen:=1;

            delay until czas+microseconds(100); --czestotliwosc 1 kHz - okres 1ms, wypełnienie 10%(100us)

            pin_gen:=0;

            delay until czas+milliseconds(1);

            czas:=czas+milliseconds(1);

        end loop;

    end if;

end loop;

end generator;

 

--czujnik cofania

type ton is(wysoki, niski, cisza);

 

task czujnik;

 

task body czujnik is

    Odleglosc:float; --tylko do odczytu, zawiera zawsze aktualną odległość

    Buczek:Ton; -- głosnik, tylko do zapisu

    dist:float; --zm pomocnicza

    Bieg wsteczny:boolean; --tylko do odczytu

begin

    loop                               --petla nieskonczona

        buczek:=cisza;

        while bieg_wsteczny loop

            dist:=odleglosc;            --Jupi powiedział, że wypadałoby tak zrobić, bo odleglosc może sie zmienić przy przechodzeniu if'a i moglby być problem

            if dist>80 then        --sprawdzanie "if buczek/=cisza" (żeby nie wysyłać sygnału niepotrzebnie) jest błędne, bo zmienna jest tylko do zapisu

...

Zgłoś jeśli naruszono regulamin