?? 2.vhd.bak
字號:
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
entity shoupiao is
port
( clk :in std_logic;
cancel:in std_logic:='1';
reset : in std_logic:='1';
ok :in std_logic:='1';
destination:in std_logic_vector(2 downto 0);
initial : in std_logic_vector(2 downto 0);
number : in std_logic_vector(1 downto 0);;
paper1: in std_logic;
paper2:in std_logic;
paper5:in std_logic;
paper10:in std_logic;
paper20:in std_logic;
comeout: out std_logic;
charge: out std_logic_vector(4 downto 0);
);
end shoupiao;
architecture behave of shoupiao is
type state is (s0,s1,s2,s3);
signal s : state;
begin
process(clk,reset)
variable money: integer:=0;
variable cost : std_logic_vector(4 downto 0):="00000";
variable trip : std_logic_vector(2 downto 0):="000";
begin
if reset='1' then
s<=s0;
else
if clk'event and clk='1' then
case s is
when s0=>
if ok='1' then
s<=s1;
else
s<=s0;
end if;
when s1=>
if destination /= initial then
if destination > initial then
trip:=(destination-initial);
elsif destination<initial then
trip:=(initial-destination);
end if;
s<=s2;
else
s<=s1;
end if;
when s2=>
if cancel='1' then
s<=s1;
end if;
if number="01" then
if trip<="100" then
cost:="00100";---5 yuan
else cost:="01000";---10 yuan
end if;
s<=s3;
elsif number="10" then
if trip<="100" then
cost:="01000"; ---10 yuan
else cost:="10000";---20 yuan
end if;
s<=s3;
elsif number="11" then
if trip<="100" then
cost:="01100";---15 yuan
else cost:="11000";---30 yuan
end if;
s<=s3;
else s<=s2;
end if;
when s3=>
if cancel='1' then
s<=s1;
end if;
money<=paper1+2*paper2+5*paper5+10*paper10+20*paper20;
if money=cost then
comeout<='1';
elsif money>=cost then
comeout<='1';
charge<=money-cost;
else s<=s3;
end if;
end case;
end if;
end if;
end process;
end behave;
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -