?? automat.vhd
字號:
library IEEE;
use IEEE.STD_LOGIC_1164.all;
entity Automat is
port(
clk,rst:in STD_LOGIC;
din: in STD_LOGIC_VECTOR(1 downto 0);
choice:in STD_LOGIC_VECTOR(1 downto 0);
commodity:out STD_LOGIC_VECTOR(1 downto 0);
give_change:out STD_LOGIC_VECTOR(1 downto 0)
);
end Automat ;
architecture behavior of Automat is
type states is (st0,st1,st2,st3,st4,st5);
signal cur_state,next_state : states;
begin
process(clk,rst)
begin
if rst='1' then
cur_state<=st0;
elsif clk'event and clk='1' then
cur_state<=next_state;
end if;
end process;
process(cur_state,next_state,din,choice)
begin
case cur_state is
when st0=>
if din="01" then next_state<=st1; --投一元
elsif din="10" then next_state<=st2; --投二元
elsif din="11" then next_state<=st5; --投五元
else next_state<=st0;
end if;
commodity<="00"; --不送商品
give_change<="00"; --不找錢
when st1=>
if din="01" then next_state<=st2; --投一元
elsif din="10" then next_state<=st3; --投二元
else next_state<=st1;
end if;
commodity<="00"; --不送商品
give_change<="00"; --不找錢
when st2=>
if din="01" then next_state<=st3; --投一元
elsif din="10" then next_state<=st4; --投二元
else next_state<=st2;
end if;
commodity<="00"; --不送商品
give_change<="00"; --不找錢
when st3=>
if din="01" then next_state<=st4; --投一元
else next_state<=st3;
end if;
if choice="01" then --選擇商品一
commodity<="01"; --送出商品一
give_change<="00"; --不找錢
next_state<=st0;
end if;
when st4=>
if choice="01" then --選擇商品一
commodity<="01"; --送出商品一
give_change<="01"; --找一元
next_state<=st0;
elsif choice="10" then --選擇商品二
commodity<="10"; --送出商品二
give_change<="00"; --不找錢
next_state<=st0;
end if;
when st5=>
if choice="01" then --選擇商品一
commodity<="01"; --送出商品一
give_change<="10"; --找二元
next_state<=st0;
elsif choice="10" then --選擇商品二
commodity<="10"; --送出商品二
give_change<="01"; --找一元
next_state<=st0;
end if;
when others =>
commodity<="00";
give_change<="00";
next_state<=st0;
end case;
end process;
end behavior;
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -