📄 ticketssellmachinetext.vhd
字号:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity ticketssellmachinetext is
port (
clk,reset: in std_logic;
select_station1 : in std_logic;
select_station2 : in std_logic;
select_station3 : in std_logic;
select_station4 : in std_logic;
select_station5 : in std_logic;
select_station6 : in std_logic;
select_station7 : in std_logic;
select_num1: in std_logic;
select_num2: in std_logic;
select_num3: in std_logic;
coin_pointfive_in,coin_one_in,
one_in,two_in,five_in,ten_in:in std_logic;
select_cancel: in std_logic;
twoyuanticket_out: out std_logic;
fouryuanticket_out : out std_logic;
ticketnumber_out:out std_logic_vector(1 downto 0);
coin_out : out std_logic_vector(3 downto 0);
coin_pointfive_out:out std_logic;
sell_out : out std_logic
);
end ticketssellmachinetext;
architecture Behave of ticketssellmachinetext is
signal station_this: std_logic_vector(2 downto 0);
signal distance: std_logic_vector(2 downto 0);
signal twoyuanticket_out_copy: std_logic;
signal fouryuanticket_out_copy : std_logic;
signal ticketnumber_out_copy1 :std_logic ;
signal ticketnumber_out_copy2 :std_logic ;
signal ticketnumber_out_copy3:std_logic ;
signal clean :std_logic;
begin
first_reset:process(clk)
begin
if(clk'event and clk='1')then
if(reset='1')then
if(select_station1='1')then station_this<="001";
elsif(select_station2='1')then station_this<="010";
elsif(select_station3='1')then station_this<="011";
elsif(select_station4='1')then station_this<="100";
elsif(select_station5='1')then station_this<="101";
elsif(select_station6='1')then station_this<="110";
elsif(select_station7='1')then station_this<="111";
end if;
end if;
end if;
end process first_reset;
get_station:process(clk)
variable select_station: std_logic_vector(2 downto 0);
begin
if(clk'event and clk='1')then
if(reset='1' or select_cancel='1' or clean='1' ) then
select_station:="000";
elsif(select_station1='1')then select_station:="001";
elsif(select_station2='1')then select_station:="010";
elsif(select_station3='1')then select_station:="011";
elsif(select_station4='1')then select_station:="100";
elsif(select_station5='1')then select_station:="101";
elsif(select_station6='1')then select_station:="110";
elsif(select_station7='1')then select_station:="111";
end if;
if(reset='1' or select_cancel='1' or clean='1' ) then
distance<="000";
select_station:="000";
elsif(select_station>station_this)then
distance<=select_station-station_this;
elsif(station_this>select_station and select_station/="000")then
distance<=station_this-select_station;
elsif(select_station=station_this)then
distance<="000";
select_station:="000";
end if;
end if;
end process get_station;
get_ticketkind: process (clk)
begin
if(clk'event and clk='1')then
if(reset='1' or select_cancel='1' or clean='1' ) then
twoyuanticket_out_copy<='0';
twoyuanticket_out<='0';
fouryuanticket_out_copy<='0';
fouryuanticket_out<='0';
elsif(distance<"100" and distance>"000")then
twoyuanticket_out_copy<='1';
twoyuanticket_out<='1';
fouryuanticket_out_copy<='0';
fouryuanticket_out<='0';
elsif(distance>"011")then
fouryuanticket_out_copy<='1';
fouryuanticket_out<='1';
twoyuanticket_out_copy<='0';
twoyuanticket_out<='0';
end if;
end if;
end process get_ticketkind;
get_ticketnum: process (clk)
begin
if(clk'event and clk='1')then
if(reset='1' or select_cancel='1' or clean='1' )then
ticketnumber_out_copy1<='0';
ticketnumber_out_copy2<='0';
ticketnumber_out_copy3<='0';
elsif(select_num1='1')then
ticketnumber_out_copy1<='1';
ticketnumber_out_copy2<='0';
ticketnumber_out_copy3<='0';
elsif (select_num2='1')then
ticketnumber_out_copy1<='0';
ticketnumber_out_copy2<='1';
elsif (select_num3='1')then
ticketnumber_out_copy1<='0';
ticketnumber_out_copy2<='0';
ticketnumber_out_copy3<='1';
end if;
end if;
end process get_ticketnum;
ticketnumber_out<= "01" when ticketnumber_out_copy1='1' else
"10" when ticketnumber_out_copy2='1' else
"11" when ticketnumber_out_copy3='1' else
"00";
deal:process(clk)
variable money_coinone_in :std_logic_vector(3 downto 0);
variable money_one_in :std_logic_vector(3 downto 0);
variable money_two_in :std_logic_vector(3 downto 0);
variable money_five_in :std_logic_vector(3 downto 0);
variable money_ten_in:std_logic_vector(3 downto 0);
variable money_pointfive_in :std_logic_vector(3 downto 0);
variable money_pointfive_state :std_logic;
variable money_in_totalcopy:std_logic_vector(3 downto 0);
variable money_in_total:std_logic_vector(3 downto 0);
variable money_needed :std_logic_vector(3 downto 0);
begin
if(clk'event and clk='1')then
if(coin_one_in='1')then
money_coinone_in:="0001";
else
money_coinone_in:="0000";
end if;
if(one_in='1')then
money_one_in:="0001";
else
money_one_in:="0000";
end if;
if(two_in='1')then
money_two_in:="0010";
else
money_two_in:="0000";
end if;
if(five_in='1')then
money_five_in:="0101";
else
money_five_in:="0000";
end if;
if(ten_in='1')then
money_ten_in:="1010";
else money_ten_in:="0000";
end if;
if(coin_pointfive_in='1')then
if(money_pointfive_state='0')then
money_pointfive_state:='1';
coin_pointfive_out<='1';
money_pointfive_in:="0000";
elsif(money_pointfive_state='1')then
money_pointfive_in:="0001";
money_pointfive_state:='0';
coin_pointfive_out<='0';
end if;
else money_pointfive_in:="0000";
end if;
if(reset='1' or clean='1')then
money_in_total:="0000";
money_in_totalcopy:="0000";
coin_pointfive_out<='0';
else
money_in_total:=money_coinone_in+money_one_in+money_two_in+money_five_in+money_ten_in+money_pointfive_in+money_in_total;
money_in_totalcopy:=money_in_total;
end if;
if(reset='1' or select_cancel='1' or clean='1')then
money_needed :="0000";
elsif( twoyuanticket_out_copy='1' and ticketnumber_out_copy1='1')then
money_needed :="0010";
elsif (twoyuanticket_out_copy='1' and ticketnumber_out_copy2='1')then
money_needed :="0100";
elsif (twoyuanticket_out_copy='1' and ticketnumber_out_copy3='1')then
money_needed :="0110";
elsif (fouryuanticket_out_copy='1' and ticketnumber_out_copy1='1')then
money_needed :="0100";
elsif (fouryuanticket_out_copy='1' and ticketnumber_out_copy2='1')then
money_needed :="1000";
elsif (fouryuanticket_out_copy='1' and ticketnumber_out_copy3='1')then
money_needed :="1100";
else
money_needed :="0000";
end if;
if(reset='1' or clean='1' )then
money_in_totalcopy:="0000";
coin_out<="0000";
money_pointfive_state:='0';
coin_pointfive_out<='0';
sell_out<='0';
clean<='0';
elsif(select_cancel='1')then
coin_out<=money_in_totalcopy;
sell_out<='1';
clean<='1'; --好容易才弄出来哈
elsif(money_in_totalcopy>=money_needed and money_in_totalcopy>0 and money_needed>0)then
coin_out<=money_in_total-money_needed;
clean<='1';
sell_out<='1';
end if;
end if;
end process deal;
end Behave;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -