用vhdl语言编写一个自动售货机,急!

\u7528VHDL\u8bed\u8a00\u8bbe\u8ba1\u4e00\u4e2a\u81ea\u52a8\u552e\u8d27\u673a

\u5df2\u53d1\u8bf7\u67e5\u6536\uff0c\u68c0\u9a8c\u662f\u5426\u6b63\u786e\uff0c\u5982\u6709\u9519\u8bef\u8bf7\u8ffd\u95ee

\u81ea\u52a8\u552e\u8d27\u673aVHDL\u7a0b\u5e8f
\uff081\uff09\u81ea\u52a8\u552e\u8d27\u673aVHDL\u7a0b\u5e8f\u5982\u4e0b\uff1a
--\u6587\u4ef6\u540d\uff1apl_auto1.vhd\u3002

--\u529f\u80fd\uff1a\u8d27\u7269\u4fe1\u606f\u5b58\u50a8\uff0c\u8fdb\u7a0b\u63a7\u5236\uff0c\u786c\u5e01\u5904\u7406\uff0c\u4f59\u989d\u8ba1\u7b97\uff0c\u663e\u793a\u7b49\u529f\u80fd\u3002

--\u8bf4\u660e\uff1a\u663e\u793a\u7684\u94b1\u6570coin\u7684\u4ee55\u89d2\u4e3a\u5355\u4f4d\u3002

library ieee;

use ieee.std_logic_arith.all;

use ieee.std_logic_1164.all;

use ieee.std_logic_unsigned.all;

entity PL_auto1 is

port ( clk:in std_logic; --\u7cfb\u7edf\u65f6\u949f
set,get,sel,finish: in std_logic; --\u8bbe\u5b9a\u3001\u4e70\u3001\u9009\u62e9\u3001\u5b8c\u6210\u4fe1\u53f7
coin0,coin1: in std_logic; --5\u89d2\u786c\u5e01\u30011\u5143\u786c\u5e01
price,quantity :in std_logic_vector(3 downto 0); --\u4ef7\u683c\u3001\u6570\u91cf\u6570\u636e

item0 , act:out std_logic_vector(3 downto 0); --\u663e\u793a\u3001\u5f00\u5173\u4fe1\u53f7

y0,y1 :out std_logic_vector(6 downto 0); --\u94b1\u6570\u3001\u5546\u54c1\u6570\u91cf\u663e\u793a\u6570\u636e

act10,act5 :out std_logic); --1\u5143\u786c\u5e01\u30015\u89d2\u786c\u5e01

end PL_auto1;

architecture behav of PL_auto1 is

type ram_type is array(3 downto 0)of std_logic_vector(7 downto 0);

signal ram :ram_type; --\u5b9a\u4e49RAM

signal item: std_logic_vector(1 downto 0); --\u5546\u54c1\u79cd\u7c7b

signal coin: std_logic_vector(3 downto 0); --\u5e01\u6570\u8ba1\u6570\u5668

signal pri,qua:std_logic_vector(3 downto 0); --\u5546\u54c1\u5355\u4ef7\u3001\u6570\u91cf

signal clk1: std_logic; --\u63a7\u5236\u7cfb\u7edf\u7684\u65f6\u949f\u4fe1\u53f7

begin

com:process(set,clk1)

variable quan:std_logic_vector(3 downto 0);

begin

if set='1' then ram(conv_integer(item))<=price & quantity;act<="0000";

--\u628a\u5546\u54c1\u7684\u5355\u4ef7\u3001\u6570\u91cf\u7f6e\u5165\u5230RAM

elsif clk1'event and clk1='1' then act5<='0'; act10<='0';

if coin0='1' then

if coin<"1001"then coin<=coin+1; --\u6295\u51655\u89d2\u786c\u5e01\uff0ccoin\u81ea\u52a01

else coin<="0000";

end if;

elsif coin1='1' then

if coin<"1001"then coin<=coin+2; --\u6295\u51651\u5143\u786c\u5e01\uff0ccoin\u81ea\u52a02

else coin<="0000";

end if;

elsif sel='1' then item<=item+1; --\u5bf9\u5546\u54c1\u8fdb\u884c\u5faa\u73af\u9009\u62e9

elsif get='1' then --\u5bf9\u5546\u54c1\u8fdb\u884c\u8d2d\u4e70

if qua>"0000" and coin>=pri then coin<=coin-pri;quan:=quan-1;

ram(conv_integer(item))<=pri & quan;

if item="00" then act<="1000"; --\u8d2d\u4e70\u65f6\uff0c\u81ea\u52a8\u552e\u8d27\u673a\u5bf94\u79cd\u5546\u54c1\u7684\u64cd\u4f5c

elsif item="01" then act<="0100";

elsif item="10" then act<="0010";

elsif item="11" then act<="0001";

end if;

end if;

elsif finish='1' then --\u7ed3\u675f\u4ea4\u6613\uff0c\u9000\u5e01\uff08\u627e\u5e01\uff09

if coin>"0001" then act10<='1';coin<=coin-2; --\u6b64IF\u8bed\u53e5\u5b8c\u6210\u627e\u5e01\u64cd\u4f5c

elsif coin>"0000" then act5<='1'; coin<=coin-1;

else act5<='0'; act10<='0';

end if;

elsif get='0' then act<="0000";

for i in 4 to 7 loop

pri(i-4)<=ram (conv_integer(item))(i); --\u5546\u54c1\u5355\u4ef7\u7684\u8bfb\u53d6

end loop;

for i in 0 to 3 loop

quan(i):=ram(conv_integer(item))(i); --\u5546\u54c1\u6570\u91cf\u7684\u8bfb\u53d6

end loop;

end if;

end if;

qua<=quan;

end process com;



m32:process(clk) --\u6b64\u8fdb\u7a0b\u5b8c\u6210\u5bf932Mhz\u7684\u8109\u51b2\u5206\u9891

variable q: std_logic_vector( 24 downto 0);

begin

if clk'event and clk='1' then q:=q+1;

end if;

if q="111111111111111111111111" then clk1<='1';

else clk1<='0';

end if;

end process m32;



code0:process(item) --\u5546\u54c1\u6307\u793a\u706f\u8bd1\u7801

begin

case item is

when "00"=>item0<="0111";

when "01"=>item0<="1011";

when "10"=>item0<="1101";

when others=>item0<="1110";

end case;

end process;



code1: process (coin) --\u94b1\u6570\u7684BCD\u5230\u4e03\u6bb5\u7801\u7684\u8bd1\u7801

begin

case coin is

when "0000"=>y0<="0000001";

when "0001"=>y0<="1001111";

when "0010"=>y0<="0010010";

when "0011"=>y0<="0000110";

when "0100"=>y0<="1001100";

when "0101"=>y0<="0100100";

when "0110"=>y0<="0100000";

when "0111"=>y0<="0001111";

when "1000"=>y0<="0000000";

when "1001"=>y0<="0000100";

when others=>y0<="1111111";

end case;

end process;



code2: process (qua) --\u5355\u4ef7\u7684BCD\u5230\u4e03\u6bb5\u7801\u7684\u8bd1\u7801

begin

case qua is

when "0000"=>y1<="0000001";

when "0001"=>y1<="1001111";

when "0010"=>y1<="0010010";

when "0011"=>y1<="0000110";

when "0100"=>y1<="1001100";

when "0101"=>y1<="0100100";

when "0110"=>y1<="0100000";

when "0111"=>y1<="0001111";

when "1000"=>y1<="0000000";

when "1001"=>y1<="0000100";

when others=>y1<="1111111";

end case;

end process;

end behav;

我之前写了个差不多的,你改改数据就行:
module shoumaiji (clk,a,b,duanxuan,weixuan,out,out1);
input clk;
input a,b; //a为投入0.5元信号,b为投入1元信号
output [8:1]duanxuan;//输出8位段选信号
output weixuan;//输出1位位选信号
output out; //out为高电平时售卖机闸门打开,汽水掉出来
output out1; //out1为高电平时候找0.5元

reg weixuan;
reg [8:1]duanxuan;
reg [31:0]count; //数码管动态扫描计数
reg [31:0]count1; //用于计算售卖机闸门打开时间
reg [4:1]a1,b1; //用a1,b1寄存投入的0.5元和1元硬币数目
reg out,out1;

always @(posedge a or posedge out)
begin
if(out==1) a1<=0;//汽水出来后计数值清零
else a1<=a1+4'b1;
end

always @(posedge b or posedge out)
begin
if(out==1) b1<=0;//汽水出来后计数值清零
else b1<=b1+4'b1;
end

always@(posedge clk) //1KHz时钟
begin
if(a1==5) out<=1; //因为汽水为2.5,可以给5个0.5元
else if(a1==3&&b1==1) out<=1; //可以给3个0.5元和1个1元
else if(a1==1&&b1==2) out<=1; //,可以给1个0.5元和2个1元
else if(b1==3)begin out<=1;out1<=1;end //可以给3个一块的,系统找回0.5元
else if(a1==0&&b1==0) //如果没人投币,则两位数码管显示0
begin
if(count==50) //如果实际运行中发现数码管有闪烁,可以将此数值调小
begin
weixuan<=1'b0;
duanxuan<=8'b00111111; //0
end

if(count==100) //如果实际运行中发现数码管有闪烁,可以将此数值调小
begin
weixuan<=1'b1;
duanxuan<=8'b00111111; //0
count<=0;
end
end
else if(a==1) //投币0.5元,显示0.5,假设数码管为共阴极的
begin
count<=count+1;
if(count==50) //如果实际运行中发现数码管有闪烁,可以将此数值调小
begin
weixuan<=1'b0;
duanxuan<=8'b01101101; //5
end

if(count==100) //如果实际运行中发现数码管有闪烁,可以将此数值调小
begin
weixuan<=1'b1;
duanxuan<=8'b10111111; //0.
count<=0;
end
end

else if(b==1) //投币1元,显示01
begin
count<=count+1;
if(count==50) //如果实际运行中发现数码管有闪烁,可以将此数值调小
begin
weixuan<=1'b0;
duanxuan<=8'b00000110; //1
end
if(count==100) //如果实际运行中发现数码管有闪烁,可以将此数值调小
begin
weixuan<=1'b1;
duanxuan<=8'b00111111; //0
count<=0;
end
end

if(out==1)
begin
if(count1==3000)//让闸门打开3秒,由于为1KHz时钟,故要数3000下
begin
out<=0;
out1<=0;
count1<=0;
end
else count1<=count1+1;
end

end
endmodule

我之前写了个差不多的,你改改数据就行:
module
shoumaiji
(clk,a,b,duanxuan,weixuan,out,out1);
input
clk;
input
a,b;
//a为投入0.5元信号,b为投入1元信号
output
[8:1]duanxuan;//输出8位段选信号
output
weixuan;//输出1位位选信号
output
out;
//out为高电平时售卖机闸门打开,汽水掉出来
output
out1;
//out1为高电平时候找0.5元
reg
weixuan;
reg
[8:1]duanxuan;
reg
[31:0]count;
//数码管动态扫描计数
reg
[31:0]count1;
//用于计算售卖机闸门打开时间
reg
[4:1]a1,b1;
//用a1,b1寄存投入的0.5元和1元硬币数目
reg
out,out1;
always
@(posedge
a
or
posedge
out)
begin
if(out==1)
a1<=0;//汽水出来后计数值清零
else
a1<=a1+4'b1;
end
always
@(posedge
b
or
posedge
out)
begin
if(out==1)
b1<=0;//汽水出来后计数值清零
else
b1<=b1+4'b1;
end
always@(posedge
clk)
//1KHz时钟
begin
if(a1==5)
out<=1;
//因为汽水为2.5,可以给5个0.5元
else
if(a1==3&&b1==1)
out<=1;
//可以给3个0.5元和1个1元
else
if(a1==1&&b1==2)
out<=1;
//,可以给1个0.5元和2个1元
else
if(b1==3)begin
out<=1;out1<=1;end
//可以给3个一块的,系统找回0.5元
else
if(a1==0&&b1==0)
//如果没人投币,则两位数码管显示0
begin
if(count==50)
//如果实际运行中发现数码管有闪烁,可以将此数值调小
begin
weixuan<=1'b0;
duanxuan<=8'b00111111;
//0
end
if(count==100)
//如果实际运行中发现数码管有闪烁,可以将此数值调小
begin
weixuan<=1'b1;
duanxuan<=8'b00111111;
//0
count<=0;
end
end
else
if(a==1)
//投币0.5元,显示0.5,假设数码管为共阴极的
begin
count<=count+1;
if(count==50)
//如果实际运行中发现数码管有闪烁,可以将此数值调小
begin
weixuan<=1'b0;
duanxuan<=8'b01101101;
//5
end
if(count==100)
//如果实际运行中发现数码管有闪烁,可以将此数值调小
begin
weixuan<=1'b1;
duanxuan<=8'b10111111;
//0.
count<=0;
end
end
else
if(b==1)
//投币1元,显示01
begin
count<=count+1;
if(count==50)
//如果实际运行中发现数码管有闪烁,可以将此数值调小
begin
weixuan<=1'b0;
duanxuan<=8'b00000110;
//1
end
if(count==100)
//如果实际运行中发现数码管有闪烁,可以将此数值调小
begin
weixuan<=1'b1;
duanxuan<=8'b00111111;
//0
count<=0;
end
end
if(out==1)
begin
if(count1==3000)//让闸门打开3秒,由于为1KHz时钟,故要数3000下
begin
out<=0;
out1<=0;
count1<=0;
end
else
count1<=count1+1;
end
end
endmodule

  • 鐢╲hdl璇█缂栧啓涓涓嚜鍔ㄥ敭璐鏈,鎬!
    绛旓細if(a1==5) out<=1; //鍥犱负姹芥按涓2.5锛屽彲浠ョ粰5涓0.5鍏 else if(a1==3&&b1==1) out<=1; //鍙互缁3涓0.5鍏冨拰1涓1鍏 else if(a1==1&&b1==2) out<=1; //锛屽彲浠ョ粰1涓0.5鍏冨拰2涓1鍏 else if(b1==3)begin out<=1;out1<=1;end //鍙互缁3涓竴鍧楃殑锛岀郴...
  • 鐢╒HDL璇█鎴朧erilog璇█缂栧啓绠鍗鑷姩鍞揣鏈
    绛旓細鏀规垚VHDL 灏卞彲浠ヤ簡 鐢ㄧ姸鎬佹満鍐欑殑 /*淇″彿瀹氫箟锛歝lk锛氭椂閽熻緭鍏ワ紱reset锛氫负绯荤粺澶嶄綅淇″彿锛沨alf_dollar锛氫唬琛ㄦ姇鍏5瑙掔‖甯侊紱one_dollar锛氫唬琛ㄦ姇鍏1鍏冪‖甯侊紱half_out锛氳〃绀烘壘闆朵俊鍙凤紱dispense锛氳〃绀烘満鍣ㄥ敭鍑轰竴鐡堕ギ鏂欙紱collect锛氳淇″彿鐢ㄤ簬鎻愮ず鎶曞竵鑰呭彇璧伴ギ鏂欍/ module sell(one_dollar,half_dollar,collect,half...
  • VHDL璇█缂栧啓鑷姩鍞揣鏈
    绛旓細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'...
  • 璁捐涓涓嚜鍔ㄥ敭楗枡鏈虹殑鎺у埗閫昏緫鐢佃矾銆鐢╒HDL璇█瀹炵幇銆
    绛旓細port (cp,x0,x1: in std_logic;rst: in std_logic;q0,q1,y0,y1: out std_logic);end text3;architecture func_comp of text3 is signal xtemp: std_logic_vector(1 downto 0);signal t1,t0: std_logic;type s is (s0,s1,s2);signal stemp: s;begin process (cp,x1,x0,rst)b...
  • vhdl缂鐨鑷姩鍞エ鏈 鍑虹幇it does not hold its value outside the cloc...
    绛旓細鎴栬呬綘涓嶆兂鍐檈nd if 灏辫鎶奺lse 鍜宨f杩炶捣鏉ュ啓鎴恊lsif锛岃繖鏍峰彧瑕鍐欎竴涓end if灏辫浜嗐傝繕鏈変竴浜涘叾浠栭敊璇紝宸叉敼濂戒笖缂栬瘧閫氳繃 LIBRARY IEEE;USE IEEE.STD_LOGIC_1164.ALL;USE IEEE.STD_LOGIC_UNSIGNED.ALL;ENTITY KUOPIN1 IS PORT(EN,CLK,SIN:IN STD_LOGIC;SIG_OUT:OUT STD_LOGIC);END KUOPIN1;...
  • VHDL,甯繖杩涙潵鐪嬬湅鍚
    绛旓細price1,price2,price3:in std_logic;y0,y1:out std_logic;payback,money:out std_logic_vector(3 downto 0));end shouhuoji;architecture behav of shouhuoji is signal coin:std_logic_vector(3 downto 0):=(others=>'0');signal cout:std_logic_vector(3 downto 0):=(others=>'0');...
  • 鑷姩鍞揣鏈哄伐浣滃師鐞
    绛旓細涓銆鑷姩鍞揣鏈哄伐浣滃師鐞嗭細宸ヤ綔鍘熺悊绮楃暐鐨勮灏辨槸鏈夎揣鏃讹紝璇嗗埆鎺ユ敹璐у竵锛岄【瀹㈤夎揣锛屽垽鏂姇鍏ラ噾棰濇槸鍚﹀銆佹満鍐呴浂閽辨槸鍚﹀鎵鹃浂锛屽嚭璐э紝鎵鹃浂銆傜幇浠g殑鑷姩鍞揣鏈虹殑鍐呴儴鎺у埗绯荤粺閲囩敤VHDL鎻忚堪璇█锛岀敤鏈夐檺鐘舵佹満杩涜绯荤粺鐘舵佹弿杩帮紝閫氱數澶嶄綅鍚庣郴缁熻嚜鍔ㄥ垵濮嬪寲锛屾牴鎹鐣岃緭鍏ョ殑淇″彿杞崲涓嶅悓鐨勭姸鎬侊紙濡傛姇甯佺姸鎬併侀攢鍞姸鎬...
  • 鑷姩鍞揣鏈哄師鐞
    绛旓細濡傛灉鏈夛紝鍚庡彴鏈嶅姟鍣ㄤ細鍚鑷姩鍞揣鏈哄彂閫佸彂璐ф寚浠わ紝鑷姩鍞揣鏈烘牴鎹寚浠ゅ彂璐с傜幇浠f櫤鑳借嚜鍔ㄥ敭璐ф満鐨勫唴閮ㄦ帶鍒剁郴缁閲囩敤VHDL鎻忚堪璇█锛岀郴缁熺殑鐘舵佺敤鏈夐檺鐘舵佹満鏉ユ弿杩般備笂鐢靛浣嶅悗锛岀郴缁熻嚜鍔ㄥ垵濮嬪寲锛屾牴鎹閮ㄨ緭鍏ヤ俊鍙疯浆鎹笉鍚岀姸鎬(濡傛姇甯佺姸鎬併侀攢鍞姸鎬併佹壘闆剁姸鎬)銆傛讳箣锛屾垜浠幇鍦ㄦ帴瑙﹀埌鐨勮嚜鍔ㄥ敭璐ф満锛屽姛鑳藉锛屽師鐞...
  • pose鏈浣跨敤浠涔璇█缂栧啓,灏忓紵涓婄彮闇瑕佸涔犳眰鏁欏悇浣
    绛旓細鐢╒HDL璇█鎴朧erilog璇█缂栧啓绠鍗鑷姩鍞揣鏈
  • 鑷姩鍞揣鏈哄師鐞
    绛旓細鑷姩鍞揣鏈 #鐢靛瓙鏀粯 #鏀粯搴旂敤浜岀淮鐮 #VHDL鎻忚堪璇█ #鏈夐檺鐘舵佹満 #鎻愯揣鐮 #鎶藉鐮 #鍚庡彴鏈嶅姟鍣ㄩ獙璇
  • 扩展阅读:verilog hdl语言 ... vhdl经典教程 ... vba编程必背50个程序 ... vhdl语言入门教程 ... vhdl写一个4位全加器 ... verilog用什么软件编写 ... vb语言为什么被淘汰了 ... 写出四选一的vhdl程序 ... vhdl语言官网 ...

    本站交流只代表网友个人观点,与本站立场无关
    欢迎反馈与建议,请联系电邮
    2024© 车视网