You are on page 1of 2

Хід роботи:

Схема:

Код:
library IEEE;
use IEEE.std_logic_1164.all;

entity state_machine is
port (
A1, A2, RESET, CLK: in STD_LOGIC;
D: out STD_LOGIC
);
end;

architecture behavioral of state_machine is


type Sreg_type is (S0, S1, S2, S3, S4 , S5);
signal Sreg: Sreg_type;
begin
process (CLK)
begin
if RESET = '1' then
Sreg <= S0;
else if CLK = '1' and CLK'event then
case Sreg is
when S0 =>
if A1 ='0' and A2 = '0' then
Sreg <= S1;
elsif A1 ='0' and A2 = '1' then
Sreg <= S2;
elsif A1 ='1' and A2 = '1' then
Sreg <= S3;
nd if;

when S1 =>
if A2 ='0' then
Sreg <= S0;
end if;

when S2 =>
if A1 ='1' and A2 = '0' then
Sreg <= S4;
end if;

when S3 =>
if A1 ='0' then
Sreg <= S0;
elsif A2 = '1' then
Sreg <= S5;
end if;

when S4 =>
if A2 = '0' then
Sreg <= S1;
elsif A1 = '0' then
Sreg <= S5;
end if;

when S5 =>
if A1 ='1' then
Sreg <= S3;
end if;
when others =>
null;
end case;
end if;
end if;
end process;
D <= '1' when (Sreg = S2) else '0';
end behavioral;
Результат роботи:

Висновок:
В ході лабораторної роботи змоделювали машину станів у проекті VHDL.

You might also like