?? 1.vhd
字號:
---選擇站點,算出票價(既2元,4 元)
選擇票數,算出所需要的錢(票數分1張,兩張,三張,四張)
投幣,每次計算投的錢數,或紙幣,1,2,5,10元;
比較需要的錢和投的錢
如果無余額,做出票工作
如果有余額,做出票工作,轉入找零
找零狀態
可以取消,返回選擇站點狀態
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
entity ticketsell is
port (clk :in std_logic;
coin5j :in std_logic_vector(3 downto 0);
coin1 :in std_logic_vector(3 downto 0);
paper1 :in std_logic_vector(3 downto 0);
paper2 :in std_logic_vector(3 downto 0);
paper5 :in std_logic_vector(3 downto 0);
paper10 :in std_logic_vector(3 downto 0);
station :in std_logic_vector(1 downto 0);
number :in std_logic_vector(1 downto 0);
reset :in std_logic;
ticketout :out std_logic_vector(3 downto 0);
zhaoling :out std_logic_vector(15 downto 0));
end ticketsell;
architecture behave of ticketsell is
type state_type is(s0,s1,s2);
signal state: state_type;
signal money:std_logic_vector(15 downto 0);
begin
process(clk,reset)
begin
if reset='1' then
state<=s0;
elsif clk'event and clk='1' then
case state is
when s0=>
case station is
when "01"=>
money<="0010";
state<=s1;
when "10"=>
money<="0100";
state<=s1;
when others=>null;
end case;
when s1=>
if money="0010" then
case number is
when "01"=>
money<="0010";
when "10"=>
money<="0100";
when "11"=>
money<="0110";
end case;
state<=s2;
else money="0100" then
case number is
when "01"=>
money<="0100";
when "10"=>
money<="1000";
when "11"=>
money<="1100";
end case;
state<=s2;
end if;
when s2=>
if (coin5j*0.5+coin+paper1+2*paper2+5*paper5+10*paper10)>=money then
ticketout<=number;
zhaoling<=coin5j*0.5+coin+paper1+2*paper2+5*paper5+10*paper10-money;
else state<=s1;
ticketout<="0";
zhaoling<="0"
end if;
end case;
end if;
end process;
end behave;
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -