找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 2932|回复: 2
收起左侧

fpga模拟一个自动售货机 源代码

[复制链接]
ID:393004 发表于 2018-9-3 15:27 | 显示全部楼层 |阅读模式
售货机卖出的商品价值5元,只能投入1元,2元,5元。因此需要多种状态,分别代表投入的钱数,直到投够5元显示出货状态,当超过5元时还要找零。

源代码如下:
library ieee;
use ieee.std_logic_1164.all;
entity state is
port(
  clk,reset:in std_logic;
  input : in std_logic_vector(0 to 1);
  sel : buffer std_logic_vector(0 to 2);    --片选
  show : out std_logic_vector(0 to 6);      --八位七段
  output:out std_logic_vector(0 to 1)
);
end state;
architecture behave of state is
type s_m is (s0,s1,s2,s3,s5,s6);
signal current_state,next_state:s_m;



begin
   sel<="000";
       process(reset,clk)
       begin
                    if (clk'event and clk='1') then
   current_state<=next_state;
     if reset='1' then
                  current_state<=s0;
                    end if;
                      end if;
       end process;
      
       process(current_state,input)
begin
       case current_state is
       when s0=>output<="00";
        show<="1111110";  --0
        if input="00" then next_state<=s0;
        elsif input="01" then next_state<=s1;
                       elsif input="10" then next_state<=s2;
        elsif input="11" then next_state<=s5;
        end if;
   
       when s1=>output<="00";
        show<="0110000";   --1
        if input="00" then next_state<=s1;
        elsif input="01" then next_state<=s2;
        elsif input="10" then next_state<=s3;
        elsif input="11" then next_state<=s6;
       end if;
   
       when s2=>output<="11";
  show<="0110111";   --H
  if input="00" then next_state<=s0;
  elsif input="01" then next_state<=s1;
  elsif input="10" then next_state<=s2;
  elsif input="11" then next_state<=s5;
  end if;
   
       when s3=>output<="11";
  show<="0110000";   --找1
  if input="00" then next_state<=s0;
  elsif input="01" then next_state<=s1;
  elsif input="10" then next_state<=s2;
                elsif input="11" then next_state<=s5;
  end if;
   
         
       when s5=>output<="11";
  show<="0110000";   --找1
  if input="00" then next_state<=s0;
  elsif input="01" then next_state<=s1;
                elsif input="10" then next_state<=s2;
  elsif input="11" then next_state<=s5;
  end if;
   
       when s6=>output<="11";
                show<="0110111";   --H
  if input="00" then next_state<=s0;
  elsif input="01" then next_state<=s1;
  elsif input="10" then next_state<=s2;
  elsif input="11" then next_state<=s5;
  end if;
   
      
   
end case;
                end process;
end behave;
   
   
   
回复

使用道具 举报

ID:375250 发表于 2018-12-19 19:38 | 显示全部楼层
这个是vhdl
回复

使用道具 举报

ID:453467 发表于 2018-12-24 15:13 | 显示全部楼层
复位信号建议写成:异步复位,同步释放
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表