找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 3509|回復(fù): 2
打印 上一主題 下一主題
收起左側(cè)

fpga模擬一個自動售貨機(jī) 源代碼

[復(fù)制鏈接]
跳轉(zhuǎn)到指定樓層
樓主
ID:393004 發(fā)表于 2018-9-3 15:27 | 只看該作者 回帖獎勵 |倒序瀏覽 |閱讀模式
售貨機(jī)賣出的商品價值5元,只能投入1元,2元,5元。因此需要多種狀態(tài),分別代表投入的錢數(shù),直到投夠5元顯示出貨狀態(tài),當(dāng)超過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;
   
   
   
分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏 分享淘帖 頂 踩
回復(fù)

使用道具 舉報

沙發(fā)
ID:375250 發(fā)表于 2018-12-19 19:38 | 只看該作者
這個是vhdl
回復(fù)

使用道具 舉報

板凳
ID:453467 發(fā)表于 2018-12-24 15:13 | 只看該作者
復(fù)位信號建議寫成:異步復(fù)位,同步釋放
回復(fù)

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規(guī)則

手機(jī)版|小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術(shù)交流QQ群281945664

Powered by 單片機(jī)教程網(wǎng)

快速回復(fù) 返回頂部 返回列表