欢迎来到天天文库
浏览记录
ID:55277100
大小:187.00 KB
页数:8页
时间:2020-05-08
《自动售货机VHDL程序与仿真.doc》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、自动售货机VHDL程序与仿真(1)自动售货机VHDL程序如下:--文件名:pl_auto1.vhd。--功能:货物信息存储,进程控制,硬币处理,余额计算,显示等功能。--说明:显示的钱数coin的以5角为单位。--最后修改日期:2004.3.23。libraryieee;useieee.std_logic_arith.all;useieee.std_logic_1164.all;useieee.std_logic_unsigned.all;entityPL_auto1isport(clk:instd_logic;--系统时钟set,get,sel,finish
2、:instd_logic;--设定、买、选择、完成信号coin0,coin1:instd_logic;--5角硬币、1元硬币price,quantity:instd_logic_vector(3downto0);--价格、数量数据item0,act:outstd_logic_vector(3downto0);--显示、开关信号y0,y1:outstd_logic_vector(6downto0);--钱数、商品数量显示数据act10,act5:outstd_logic);--1元硬币、5角硬币endPL_auto1;architecturebehavofPL_
3、auto1istyperam_typeisarray(3downto0)ofstd_logic_vector(7downto0);signalram:ram_type;--定义RAMsignalitem:std_logic_vector(1downto0);--商品种类signalcoin:std_logic_vector(3downto0);--币数计数器signalpri,qua:std_logic_vector(3downto0);--商品单价、数量signalclk1:std_logic;--控制系统的时钟信号begincom:process(set,
4、clk1)variablequan:std_logic_vector(3downto0);beginifset='1'thenram(conv_integer(item))<=price&quantity;act<="0000";--把商品的单价、数量置入到RAMelsifclk1'eventandclk1='1'thenact5<='0';act10<='0';ifcoin0='1'thenifcoin<"1001"thencoin<=coin+1;--投入5角硬币,coin自加1elsecoin<="0000";endif;elsifcoin1='1'th
5、enifcoin<"1001"thencoin<=coin+2;--投入1元硬币,coin自加2elsecoin<="0000";endif;elsifsel='1'thenitem<=item+1;--对商品进行循环选择elsifget='1'then--对商品进行购买ifqua>"0000"andcoin>=prithencoin<=coin-pri;quan:=quan-1;ram(conv_integer(item))<=pri&quan;ifitem="00"thenact<="1000";--购买时,自动售货机对4种商品的操作elsifitem="
6、01"thenact<="0100";elsifitem="10"thenact<="0010";elsifitem="11"thenact<="0001";endif;endif;elsiffinish='1'then--结束交易,退币(找币)ifcoin>"0001"thenact10<='1';coin<=coin-2;--此IF语句完成找币操作elsifcoin>"0000"thenact5<='1';coin<=coin-1;elseact5<='0';act10<='0';endif;elsifget='0'thenact<="0000";fori
7、in4to7looppri(i-4)<=ram(conv_integer(item))(i);--商品单价的读取endloop;foriin0to3loopquan(i):=ram(conv_integer(item))(i);--商品数量的读取endloop;endif;endif;qua<=quan;endprocesscom;m32:process(clk)--此进程完成对32Mhz的脉冲分频variableq:std_logic_vector(24downto0);beginifclk'eventandclk='1'thenq:=q+1;endif;i
8、fq="111111111111111
此文档下载收益归作者所有