?? shoupiao.vhd
字號:
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;
reset : in std_logic;
ok :in std_logic;
destination:in integer range 1 to 12;
initial : in integer range 1 to 12;
number : in integer range 1 to 3;
coin05 :in std_logic;
coin1 :in std_logic;
paper1: in std_logic;
paper2:in std_logic;
paper5:in std_logic;
paper10:in std_logic;
comeout: out std_logic;
charge: out integer range 1 to 20
);
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 : integer:=0;
variable trip : integer:=0;
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=1 then
if trip<=6 then
cost:=4;
else cost:=8;
end if;
s<=s3;
elsif number=2 then
if trip<=6 then
cost:=8;
else cost:=16;
end if;
s<=s3;
elsif number=3 then
if trip<=6 then
cost:=12;
else cost:=24;
end if;
s<=s3;
else s<=s2;
end if;
when s3=>
if cancel='1' then
s<=s1;
end if;
if money=cost then
comeout<='1';
elsif money>=cost then
comeout<='1';
charge<=money-cost;
elsif coin05='1' then
money:=money+1;
elsif coin1='1' then
money:=money+2;
elsif paper1='1' then
money:=money+2;
elsif paper2='1' then
money:=money+4;
elsif paper5='1' then
money:=money+10;
elsif paper10='1' then
money:=money+20;
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 + -