logo资料库

自动售货机的设计与实现.doc

第1页 / 共1页
资料共1页,全文预览结束
VHDL 语言编写自动售货机 设计并实现一个自动售货机控制电路,某自动售货机售 A,B,C3 种商品,他们的价格分 别为 1,3,4。售票机进接受一元硬币。售货机面板上设有投币孔和退钱建,每种商品标识 处有选择按键,上有指示灯表明当前投币说是否已经足够选买该商品。 最佳答案 library ieee; use ieee.std_logic_1164.all; entity autosell is port( A,B,C:in std_logic;--3 种商品 in_money,out_money:in std_logic;--投币,和退币 out_m:out std_logic;--出币开关 Ya,Yb,Yc:out std_logic;--指示灯 ya_out,yb_out,yc_out:out std_logic);--出货信号 end; architecture behaviol of autosell is signal count:integer range 0 to 5;--技数 signal a1,b1,c1:std_logic; begin process(out_money,in_money,A,B,C) begin if in_money='1' then --投币 count<=count+1; end if; if count>0 then a1<='1';else a1<='0';end if; if count>2 then b1<='1';else b1<='0';end if; if count>4 then c1<='1';else c1<='0';end if; Ya<=a1;Yb<=b1;Yc<=c1; --指示灯亮 if (a1<='1' and A='1') then --按键选择商品 ya_out<='1';count<=count-1;else ya_out<='0'; end if; if (b1<='1' and B='1') then yb_out<='1';count<=count-3;else yb_out<='0'; end if; if (c1<='1' and C='1') then yc_out<='1';count<=count-5; else end if; yc_out<='0'; if out_money='1' then --退币 count<=0;out_m<='1'; else out_m<='0'; end if; end process; end;
分享到:
收藏