vhdl吧 关注:4,588贴子:17,611
  • 3回复贴,共1

关于地铁售票机的问题,,,求大神改改,,

只看楼主收藏回复

library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
entity ticket_select is
port(rest:in std_logic;
clk:in std_logic;
en0:in std_logic;
jia_2,jia_3,jia_4:in std_logic;
shu_1,shu_2,shu_3:in std_logic;
price:buffer std_logic_vector(3 downto 0);
quantity:out std_logic_vector(2 downto 0);
cost:out std_logic_vector(3 downto 0) --定义各输入输出端口
);
end ticket_select;
architecture behave of ticket_select is
begin
process(clk)
begin
if (en0='1') then
if (rest='0') then
price<="0000";
quantity<="000";
cost<="0000"; --先将各状态清零
elsif (clk'event and clk='1') then --等待时钟脉冲上升沿的到来
if (jia_2='1') then
price<="0010"; --选择2元的票价
elsif (jia_3='1') then
price<="0011"; --选择3元的票价
elsif (jia_4='1') then
price<="0100"; --选择4元的票价
else
price<="0000"; --没有选择票价
end if;
if (shu_1='1') then
quantity<="001"; --选择购买一张车票
cost<=price; --需要付的钱币等于票价
elsif (shu_2='1') then
quantity<="010"; --选择购买两张车票
cost<=price+price; --需要付的钱币等于票价的两倍
elsif (shu_3='1') then
quantity<="011"; --选择购买三张车票
cost<=price+price+price; --需要付的钱币等于票价的三倍
else
quantity<="000"; --没有选择票数
end if;
end if;
end if;
end process;
end behave;
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
entity give_change is
port(rest,clk,en2,bi:in std_logic;
df:in std_logic_vector(3 downto 0);
quantity:in std_logic_vector(2 downto 0);
piaoshu:out std_logic_vector(2 downto 0);
change:out std_logic_vector(3 downto 0)
); --定义各输入输出端口
end give_change;
architecture behave of give_change is
begin
process(clk)
begin
if (en2='1') then
if (rest='0') then
piaoshu<="000";
change<="0000"; --先将各状态清零
elsif (clk'event and clk='1') then --等待时钟脉冲上升沿的到来
if (bi='1') then --当使能端bi有效
piaoshu<=quantity; --输出票数为车票选择模块输出的票数
change<=df; --找零为投入钱数与总价之差
else
piaoshu<="000"; --使能端bi有效时不出票
change<=df; --找零为投入的总钱数
end if;
end if;
else null;
end if;
end process;
end behave;
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
entity zhu_kong is
port(start,clk,rest:in std_logic;
cost,money_insert:in std_logic_vector(3 downto 0);
en0,en1,en2,bi:out std_logic;
df:out std_logic_vector(3 downto 0) --定义各输入输出端口
);
end zhu_kong;
architecture behave of zhu_kong is
begin
process(clk)
begin
if (rest='0') then
en0<='0'; en1<='0';en2<='0';
bi<='0';
df<="0000"; --先将各状态清零
elsif (clk'event and clk='1') then --等待时钟脉冲上升沿的到来
if (start='1') then --选择功能使能端有效时
en0<='1';en1<='1';en2<='0';
--车票选择模块,纸、硬币处理模块工作
else
en0<='0'; en1<='0';en2<='1'; --否则自动找零、出票模块工作
end if;
if (money_insert>=cost) then --当投入的总钱数>=总价时
bi<='1'; df<=money_insert-cost;
--使能端bi有效,退钱数为总钱数与总价之差
else
bi<='0'; df<=money_insert; --否则使能端无效,退钱数为总钱数
end if;
end if;
end process;
end behave;
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
entity tou_bi is
port(rest,clk,en1:in std_logic;
qian_1,qian_5,qian_10:in std_logic;
cost:in std_logic_vector(3 downto 0) ;
qian:buffer std_logic_vector(3 downto 0);
money_insert:out std_logic_vector(3 downto 0)
);
end tou_bi; --定义各输入输出端口
architecture behave of tou_bi is
begin
process(clk)
begin
if (en1='1') then
if (rest='0') then
qian<="0000";
money_insert<="0000"; --先将各状态清零
elsif (clk'event and clk='1') then --等待时钟脉冲上升沿的到来
if (qian_1='1') then
qian<="0001"; --投入一个1元硬币
elsif (qian_5='1') then
qian<="0101"; --投入一张5元纸币
elsif (qian_10='1') then
qian<="1010"; --投入一张10元纸币
else
qian<="0000"; --不投入钱
end if;
if (qian<cost) then --投入的钱数小于车票总价
if (qian_1='1') then --投入一个1元硬币
qian<=qian+"0001"; --投入的钱数加1
elsif (qian_5='1') then --投入一张5元纸币
qian<=qian+"0101"; --投入的钱数加5
elsif (qian_10='1') then --投入一张10元纸币
qian<=qian+"1010"; --投入的钱数加10
end if;
else --投入的总钱数大于或等于车票总价
money_insert<=qian; --投入的总钱数就等于投入的钱数
end if;
end if;
end if;
end process;
end behave;
在投入总钱数大于或等于车票总价时可正常出票找零;在投入总钱数少于车票总价时,无法正常退钱 。不知道什么原因


IP属地:上海1楼2017-04-13 15:40回复
    支持有偿


    IP属地:上海2楼2017-04-13 15:40
    回复
      滴滴滴


      IP属地:上海3楼2017-04-13 15:41
      回复
        顶顶顶


        IP属地:上海4楼2017-04-13 15:41
        回复