自动售货机界面操作及显示 VHDL语言

合集下载

基于FPGA的自动售货机的课设说明书

基于FPGA的自动售货机的课设说明书

目录1 引言 (1)2 VHDL介绍 (2)2.1 硬件描述语言VHDL (2)2.2 VHDL语言的特点 (3)3 QuartusII软件简介 (4)3.1软件介绍 (4)3.2界面介绍 (4)3.2.1代码输入界面 (4)3.2.2功能仿真界面 (5)3.2.3波形仿真界面 (6)4 自动售货机控制器设计与仿真 (7)4.1硬件电路设计 (7)4.2状态转换图 (7)4.3时序仿真结果 (10)5引脚锁定及下载 (12)5.1引脚锁定 (12)5.2下载 (12)5.3结果分析 (12)6设计总结 (14)参考文献 (15)附录 (16)1 引言VHDL的英文全名是VHSIC(Very High Speed Integrated Circuit)Hardware Descriptiong Language,诞生于1982年。

1987年底,VHDL被美国国防部确认为标准硬件描述语言。

自IEEE公布了VHDL的标准版本,IEEE-1076之后,各EDA公司相继推出了自己的VHDL设计环境,或宣布自己的设计工具可以和VHDL接口。

1993年,IEEE对VHDL进行了修订,从更高的抽象层次和系统描述能力上扩展VHDL的内容,公布了新版本的VHDL,即IEEE标准的1076-1993版本。

现在,VHDL和Verilog作为IEEE的工业标准硬件描述语言,又得到众多EDA公司的支持,在电子工程领域,已成为事实上的通用硬件描述语言。

有专家认为,在新的世纪中,VHDL于Verilog语言将承担起大部分的数字系统设计任务。

VHDL的英文全写(Very-High-Speed Integrated Circuit HardwareDescription Language)翻译成中文就是超高速集成电路硬件描述语言。

因此它的应用主要是应用在数字电路的设计中。

目前,它在中国的应用多数是用在FPGA/CPLD/EPLD的设计中。

基于VHDL语言的地铁自动售票系统设计与实现

基于VHDL语言的地铁自动售票系统设计与实现

摘要本文主要介绍了利用VHDL设计语言和Altera公司的MAX+PLUS II软件开发平台, 来设计实现地铁自动售票系统的核心控制部分的功能:站点选择,票数选择,投币处理,余额计算,自动出票等功能。

在本设计中采用了有限状态机的设计方法,将整个售票系统的控制部分化分为五个状态: 选站状态,选票状态,投币状态,出票状态和余额找零状态。

最后通过对程序的调试以及相应部分功能的仿真,验证了整个系统的原理和本设计方案的正确性。

由于采用了有限状态机的设计方法,使得本系统运行可靠性高,非法状态易控制。

关键词: FPGA,CPLD, VHDL语言,MAX+PLUS II 软件,有限状态机, ,地铁自动售票系统目录第一章绪论 (1)1.1 电子器件的发展和现状 (1)1.2 设计方法的发展 (3)1.3 层次化的设计与VHDL的应用 (5)1.4 本课题的提出与意义 (8)1.5 本课题研究内容 (8)第二章 VHDL语言介绍 (10)2.1什么是VHDL (10)2.2 VHDL语言的特点 (10)2.3 VHDL的设计流程 (11)2.4 VHDL程序的基本结构 (13)第三章 MAX+PLUS II软件介绍 (14)3.1 MAX+PLUS II简介 (14)3.2Max+PlusⅡ开发系统的特点 (15)3.3 Max+PlusⅡ功能简介 (16)3.4 Max+plusⅡ设计过程 (20)第四章地铁售票系统的设计与实现 (23)4.1 课题要求 (23)4.2设计分析 (23)4.3状态机设计 (25)第五章结束语 (32)附录 (33)参考文献 (40)致谢 (41)第一章绪论1.1 电子器件的发展和现状电子技术的发展总是同电子器件的发展密切相关的,由于电子器件的不断更新换代,电子技术得到了飞速发展,当今信息技术被广泛应用在国民经济的方方面面。

多媒体技术的普及、高速宽带网络的建设、数字电视的出现以及与我们日常生活息息相关的各种家用电器,都离不开微处理器、存储器和一些采用行业标准的专用芯片。

基于VHDL的自动售货机的设计和实现论文

基于VHDL的自动售货机的设计和实现论文

《计算机组成原理》课程设计报告基于VHDL的自动售货机设计与实现课程设计任务书计算机与通信工程学院网络工程专业指导教师对学生在课程设计中的评价指导教师对课程设计的评定意见基于VHDL的自动售货机设计与实现摘要:本设计运用VHDL语言编写一个自动售货机的控制系统,该系统具有货物信息存储,进程控制,硬币处理,余额计算,显示等功能。

商品的种类、单价和数量在初始化时输入,然后存储。

可以识别的币种为硬币,五毛和一元的面额。

用户投入硬币,系统累计数量,然后对比物品的单价和数量,扣除价格,最后计算余额,可以找零。

设计没有考虑硬件的实现,只进行功能的相应仿真,性质为实验性质的课程设计。

关键词:VHDL、自动售货机、课程设计、MXAPLUSⅡ、系统仿真Abstract: This design use of VHDL language design a vending machine control system, the system have the functions to storagethe goods information, process control, coin handling, balance calculation, display and other functions. The type of goods, unit price and quantity in the initialization to be input, and then stored. Currency for the coins can be identified, fifty cents and one dollar denomination. User input coins, the system account sum, and then comparing the unit price and quantity of goods, net price, the final calculation of the balance, you can give change.Design did not consider the hardware implementation, only the corresponding functional simulation, experimental nature of the curriculum design.Keywords: VHDL, vending machines, curriculum design, MXAPLUS Ⅱ, system simulation目录1.引言 (7)1.1自动售货机系统概述 (7)1.2设计任务和主要容 (8)2.系统设计过程 (9)2.1自动售货机系统总体框图 (9)2.2系统功能模块 (9)2.3程序源代码 (11)3.系统仿真 (15)3.1系统仿真全图 (15)3.2系统分步仿真图 (16)4.总结 (20)参考文献 (21)1 引言随着现在生活节奏越来越快,自动售货机的出现大大方便了人们的日常生活。

自动售货机电路设计VHDL

自动售货机电路设计VHDL

郑州轻工业学院课程设计任务书题目自动售货机电路设计专业、班级电信2班学号 541101030217 姓名李磊主要内容、基本要求、主要参考资料等:查阅资料完成自动售货机的设计思路,利用硬件编程语言VHDL 或者Verilog-HDL来实现,要求能够识别100元、50元、10元、5元及其钢崩1元五种面值的设计,能够找零,设计中假设找零货贝充裕,货物的价格不允许出现0.5元的情况。

给出完成控制电路所需要的设计模块;给出硬件编程语言的实现,并进行仿真;给出下载电路的设计,设计为2种下载方法,其中一种必须为JTAG;同时设计者报告不允许雷同。

参考资料:1、潘松、黄继业《EDA技术及其应用》(第四版)科学出版社 20092、数字信号处理的教材完成期限:指导教师签名:课程负责人签名:摘要随着电子技术的发展,当今数字系统的设计正朝着速度快,容量大,体积小,重量轻的方向发展,推动该潮流迅猛发展的引擎就是日趋进步和完善的ASIC设计技术,AISC芯片具有价格低,体积小,可靠性高等优点,目前在电子产品中已有广泛的应用,VHDL是一种用来描述数字逻辑系统的“编程语言”,它通过对硬件行为的直接描述来实现对硬件的物理实现,代表了当今硬件设计的发展方向。

本文是在VHDL的基础上对自动售货机进行设计来实现其基本功能的,采用了Altera的开发软件Quarts II。

通过在该软件平台上进行数字电路设计和仿真的方法,阐述了VHDL(Very High Speed Integrated Circuit Hardware Description Language)超高速集成电路硬件描述语言的一些特点及语法结构,介绍了自动售货机的基本原理、系统组成和主要功能,并分析讨论了用VHDL语言开发自动售货机系统的设计流程。

本设计采用VHDL硬件描述语言编程的设计方法设计系统核心电路的硬件程序,在Quartus II软件平台上进行编译和仿真。

文章首先简述了自动售货机系统的意义和发展现状以及VHDL语言的特点,然后介绍了自动售货机的设计要求、设计思路,并给出了总体设计框图,通过分析设计写出VHDL程序源代码,将代码在Quartus II软件平台上进行编译仿真,波形基本符合设计要求。

EDA自动售货机课程设计

EDA自动售货机课程设计

一、设计目的1.熟悉状态机的使用。

2.了解用VHDL语言实现状态机的过程。

二、设计内容本系统模拟一个自动售票机:所售邮票的价钱分别为:6角和8角;按键设置S1:按一下一角,S2:按一下5角,S3:按一下一元,S8:选择邮票面值,按一下当D1_1亮表示选择6角邮票,按一下D1_2亮表示选择8角邮票,S7:取消操作。

D1_6~D1_8:找回的零钱 D1_1:指示6角邮票D1_2:指示8角邮票 D1_4:提示邮票送出三、设计原理有限状态机FSM及其设计技术是实用数字系统设计中实现高效率、高可靠逻辑控制的重要途径。

传统的状态机设计方法需进行繁琐的状态分配、绘制状态表、化简次态方程等,而利用VHDL可以避免这些繁琐的过程,直接利用状态转换图进行状态机的描述,所有的状态均可表达为CASE_WHEN结构中的一条CASE语句,而状态的转移则通过IF_THEN_ELsE语句实现。

四、管脚分配实验符号对应附录符号管脚money[0] S1 PIN_66money[1] S2 PIN-67money[2] S3 PIN_68rst RESET PIN_240commodity6 D1_1 PIN_215commodity8 D1_2 PIN_217give_change[0] D1_8 PIN_224give_change[1] D1_7 PIN_225give_change[2 D1_6 PIN_213stamp S8 PIN_75back S7 PIN_76clk100hz Clock PIN_29sell D1_4 PIN_207五、使用说明本程序是一个自动处理人机信息交换的程序,它能根据人们的需要,显示邮票的面值,在付款和付款取消的时候给出相应指示,处理交易中出现的各种情况,并且能在交易后显示是否交易成功。

六、流程图设计七、程序设计如下:library ieee; 初始定义投入壹角硬币的处理电路模块投入五角硬币的处理电路模块投入壹元硬币的处理电路模块选择邮票模块确认与取消处理电路模块退币处理电路模块出货电路模块use ieee.std_logic_1164.all;use ieee.std_logic_arith.all;use ieee.std_logic_unsigned.all;entity vendor isport(reset :in std_logic; --系统内部给其他顾客重新操作的复位信号clk :in std_logic; --由外接信号发生器提供的1024Hz 系统时钟信号ok_buy :in std_logic; --购买确认的按键信号cancel_buy :in std_logic; --购买取消的按键信号coin_1 :in std_logic;-- 投入壹角硬币的动作按键coin_5 :in std_logic; --投入五角硬币的动作按键coin_10 :in std_logic; --投入壹圆硬币的动作按键select_liu_yp :in std_logic; --选择六角邮票的按键信号select_ba_yp :in std_logic; --选择八角邮票的按键信号led_liu_yp_ok :out std_logic; --灯亮显示还有六角邮票led_ba_yp_ok :out std_logic; --灯亮显示还有八角邮票led_liu_yp_sel :out std_logic; --灯亮显示六角邮票选择键被按 led_ba_yp_sel :out std_logic; --灯亮显示八角邮票选择键被按 led_buy :out std_logic; --灯亮显示按了购买确认键led_cancel :out std_logic; --灯亮显示按了购买取消键led_one :out std_logic;--1个LED,投入1个1角硬币亮一个LEDled_five :out std_logic;--3个LED,投入1个五角硬币亮一个LEDled_ten :out std_logic;--2个LED,投入1个壹圆硬币亮一个LEDDOUT:OUT STD_LOGIC_VECTOR(6 DOWNTO 0);led_liu_yp_out :out std_logic;--灯亮显示六角邮票已出货led_ba_yp_out :out std_logic --灯亮显示八角邮票已出货);end;architecture arch of vendor issignal ok :std_logic;--用来维持ok_buy的状态signal cancel :std_logic;--用来维持cancel_buy的状态signal money_ok1 :std_logic;--投入金额正确signal money_ok2 :std_logic;--投入金额正确signal return_clk :std_logic;--退币的闪烁信号4Hzsignal liu_yp_choice :std_logic;--用来维持select_liu_yp的状态 signal ba_yp_choice :std_logic;--用来维持select_ba_yp的状态signal total_amount_one:integer range 0 to 1;--壹角硬币的累计投入金额signal total_amount_five:integer range 0 to 5;--五角硬币的累计投入金额signal total_amount_ten :integer range 0 to 10;--壹圆硬币的累计投入金额signal total_amount_6 :integer range 0 to 6;--壹圆硬币的累计投入金额signal total_amount_8 :integer range 0 to 8;--壹圆硬币的累计投入金额signal liu_yp_out :std_logic;--六角邮票已经出货的信号signal ba_yp_out :std_logic;--八角邮票已经出货的信号begincoin_1_counting:block --投入壹角硬币的处理电路模块beginprocess(reset,coin_1)beginif reset='1' then total_amount_one<=0; --复位led_one<='0';elsif rising_edge(coin_1) then --按下投入一角硬币的按钮total_amount_one<=1;led_one<='1'; --灯亮几盏表示投入多少个硬币end if;end process;end block;coin_10_counting:block --投入壹圆硬币的处理电路模块beginprocess(reset,coin_10)beginif reset='1' then total_amount_ten<=0; --复位led_ten<='0';elsif rising_edge(coin_10) then --按下投入一元硬币的按钮total_amount_ten<=10;led_ten<='1'; --灯亮几盏表示投入多少个硬币end if;end process;end block;coin_5_counting:block --投入五角硬币的处理电路模块signal no_coin_five:integer range 0 to 1;beginprocess(reset,coin_5)beginif reset='1' then total_amount_five<=0; --复位led_five<='0';elsif rising_edge(coin_5) then --按下投入五角钱硬币的按钮total_amount_five<=5;led_five<='1'; --灯亮几盏表示投入多少个硬币 end if;end process;end block;select_drink:blockbeginprocess(reset,clk)beginif reset='1' then led_liu_yp_sel<='0'; --复位led_ba_yp_sel<='0';ba_yp_choice<='0';liu_yp_choice<='0';elsif rising_edge(clk) then --时钟上升沿if select_liu_yp='1' then --选择led_liu_yp_sel<='1'; --相应的信号灯亮liu_yp_choice<='1'; --维持选择状态led_ba_yp_sel<='0';ba_yp_choice<='0';end if;if select_ba_yp='1' then --选择led_liu_yp_sel<='0';ba_yp_choice<='1'; --维持选择状态led_ba_yp_sel<='1'; --相应的灯亮liu_yp_choice<='0';end if;end if;end process;end block;ok_or_cancel:block --确认与取消处理电路模块beginp1:process(reset,ok_buy)beginif reset='1' then ok<='0'; --复位led_buy<='0';elsif rising_edge(ok_buy) then --按确认按钮ok<='1'; --维持状态led_buy<='1'; --确认灯亮end if;end process;p2:process(reset,cancel_buy)beginif reset='1' then cancel<='0'; --复位led_cancel<='0';elsif rising_edge(cancel_buy) then --按取消键cancel<='1'; --维持状态led_cancel<='1'; --取消灯亮end if;end process;end block;coin_returned:block --退币处理电路模块signal total_amount:integer range 0 to 16;signal ret:integer range 0 to 16;beginprocess(reset,clk)beginif reset='1' then --复位total_amount<=0;money_ok1<='0';money_ok2<='0';DOUT<="1000000";elsif rising_edge(clk) then --时钟上升沿total_amount<=total_amount_ten+total_amount_five+total_amount_one; --投入总钱数,十进制,单位角if total_amount>=6 then money_ok1<='1';else money_ok1<='0';end if;if total_amount>=8 then money_ok2<='1';else money_ok2<='0';end if;if (cancel='1') then --取消购买CASE total_amount ISWHEN 0=>DOUT<="1000000";--0WHEN 1=>DOUT<="1111001";--1WHEN 2=>DOUT<="0100100";--2WHEN 3=>DOUT<="0110000";--3WHEN 4=>DOUT<="0011001";--4WHEN 5=>DOUT<="0010010";--5WHEN 6=>DOUT<="0000010";--6WHEN 7=>DOUT<="1111000";--7WHEN 8=>DOUT<="0000000";--8WHEN 9=>DOUT<="0010000";--9WHEN 10=>DOUT<="0001000";--10WHEN 11=>DOUT<="0000011";--11WHEN 12=>DOUT<="1000110";--12WHEN 13=>DOUT<="0100001";--13WHEN 14=>DOUT<="0000110";--14WHEN 15=>DOUT<="0001110";--15WHEN 16=>DOUT<="0001001";--16WHEN OTHERS=>DOUT<="1111111";END CASE;end if;if (money_ok1='1' and ok='1' and liu_yp_choice='1') thentotal_amount_6<=6;ret<=total_amount-total_amount_6;elsif( money_ok2='1' and ok='1' and ba_yp_choice='1') thentotal_amount_8<=8;ret<=total_amount-total_amount_8;else ret<=total_amount;end if;if ( ok='1') then --取消购买CASE ret ISWHEN 0=>DOUT<="1000000";--0WHEN 1=>DOUT<="1111001";--1WHEN 2=>DOUT<="0100100";--2WHEN 3=>DOUT<="0110000";--3WHEN 4=>DOUT<="0011001";--4WHEN 5=>DOUT<="0010010";--5WHEN 6=>DOUT<="0000010";--6WHEN 7=>DOUT<="1111000";--7WHEN 8=>DOUT<="0000000";--8WHEN 9=>DOUT<="0010000";--9WHEN 10=>DOUT<="0001000";--10WHEN 11=>DOUT<="0000011";--11WHEN 12=>DOUT<="1000110";--12WHEN 13=>DOUT<="0100001";--13WHEN 14=>DOUT<="0000110";--14WHEN 15=>DOUT<="0001110";--15WHEN 16=>DOUT<="0001001";--16WHEN OTHERS=>DOUT<="1111111";END CASE;end if;end if;end process;end block;give_check:block --出货电路模块beginliu_yp_out<='1' when (money_ok1='1' and ok='1' and liu_yp_choice='1') else '0';led_liu_yp_out<=liu_yp_out;ba_yp_out<='1' when (money_ok2='1' and ok='1' and ba_yp_choice='1') else '0';led_ba_yp_out<=ba_yp_out;end block;end arch;八、设计总结:通过这次小学期设计让我更加深入的了解了VHDL语言的使用及其设计方法,在设计过程中遇到很多问题,通过自己和小组成员的共同努力,把所遇到的问题一一克服,在解决问题的过程中对VHDL的实际应用有了很大的提高九、参考文献:[1] 高峰.单片微型计算机原理与接口技术.科学出版社,2007。

自动售货机VHDL程序与仿真

自动售货机VHDL程序与仿真

自动售货机VHDL程序与仿真(1)自动售货机VHDL程序如下:--文件名:pl_auto1.vhd。

--功能:货物信息存储,进程控制,硬币处理,余额计算,显示等功能。

--说明:显示的钱数coin的以5角为单位。

--最后修改日期:2004.3.23。

library ieee;use ieee.std_logic_arith.all;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity PL_auto1 isport ( clk:in std_logic; --系统时钟set,get,sel,finish: in std_logic; --设定、买、选择、完成信号coin0,coin1: in std_logic; --5角硬币、1元硬币price,quantity :in std_logic_vector(3 downto 0); --价格、数量数据item0 , act:out std_logic_vector(3 downto 0); --显示、开关信号y0,y1 :out std_logic_vector(6 downto 0); --钱数、商品数量显示数据act10,act5 :out std_logic); --1元硬币、5角硬币end PL_auto1;architecture behav of PL_auto1 istype ram_type is array(3 downto 0)of std_logic_vector(7 downto 0);signal ram :ram_type; --定义RAMsignal item: std_logic_vector(1 downto 0); --商品种类signal coin: std_logic_vector(3 downto 0); --币数计数器signal pri,qua:std_logic_vector(3 downto 0); --商品单价、数量signal clk1: std_logic; --控制系统的时钟信号begincom:process(set,clk1)variable quan:std_logic_vector(3 downto 0);beginif set='1' then ram(conv_integer(item))<=price & quantity;act<="0000";--把商品的单价、数量置入到RAM elsif clk1'event and clk1='1' then act5<='0'; act10<='0';if coin0='1' thenif coin<"1001"then coin<=coin+1; --投入5角硬币,coin自加1else coin<="0000";end if;elsif coin1='1' thenif coin<"1001"then coin<=coin+2; --投入1元硬币,coin自加2else coin<="0000";end if;elsif sel='1' then item<=item+1; --对商品进行循环选择elsif get='1' then --对商品进行购买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"; --购买时,自动售货机对4种商品的操作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 --结束交易,退币(找币)if coin>"0001" then act10<='1';coin<=coin-2; --此IF语句完成找币操作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 looppri(i-4)<=ram (conv_integer(item))(i); --商品单价的读取end loop;for i in 0 to 3 loopquan(i):=ram(conv_integer(item))(i); --商品数量的读取end loop;end if;end if;qua<=quan;end process com;m32:process(clk) --此进程完成对32Mhz的脉冲分频variable q: std_logic_vector( 24 downto 0);beginif 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) --商品指示灯译码begincase item iswhen "00"=>item0<="0111";when "01"=>item0<="1011";when "10"=>item0<="1101";when others=>item0<="1110";end case;end process;code1: process (coin) --钱数的BCD到七段码的译码begincase coin iswhen "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) --单价的BCD到七段码的译码begincase qua iswhen "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;(2)程序仿真图8.21.2 系统仿真全图图8.21.3 系统仿真图-预置部分图21.4 系统仿真图-商品种类选择部分图8.21.5 系统仿真图-投币部分图8.21.6 系统仿真图-购买、找币结束交易部分。

基于VHDL语言自动报货机

基于VHDL语言自动报货机

自动售报机设计一设计题目:自动售报机设计FPGA模块模拟自动售报机的工作过程,要求如下(1)售报机有两个进币孔,可以输入硬币和纸币,售报机有两个进币孔,一个是输入硬币,一个是输入纸币,硬币的识别范围是5角和1 元的硬币,纸币的识别范围是1 元、5 元,10 元,20元,50元,100元。

顾客可以连续多次投入钱币。

(2)顾客可以选择的报纸种类有3种,价格分别为1-3元,顾客可以通过输入报纸的编号来实现报纸的选择。

即有一个小键盘(0-9按键)来完成,比如输入3时要先输入0,再输入3。

(3)顾客选择完报纸后,可以选择需要的数量。

然后可以继续选择报纸及其数量,每次可以选择最多三个报纸。

然后显示出所需金额。

顾客此时可以投币,并且显示已经投币的总币值。

当投币值达到或超过所需币值后,售报机出报,并扣除所需金额,并找出多余金额。

在投币期间,顾客可以按取消键取消本次操作,钱币自动退出。

二、程序实现功能:FPGA模块模拟自动售货机:(1)售报机有两个进币孔,分别输入硬币和纸币,硬币的识别范围是5角和1 元的硬币,纸币的识别范围是1 元、5 元,10 元,20元,50元,100元。

顾客可以连续多次投入钱币。

(2)顾客可以选择的报纸种类有3种,价格分别为1-3元,顾客可以通过输入报纸的编号来实现报纸的选择。

(3)顾客选择完报纸后,可以选择需要的数量。

然后可以继续选择报纸及其数量,每种商品最多购买三份。

然后显示出所需金额。

顾客此时可以投币,并且显示已经投币的总币值。

当投币值达到或超过所需币值后,售货机出货,并扣除所需金额,并找出多余金额。

在投币期间,顾客可以按取消键取消本次操作,钱币自动退出。

三、程序功能模块分析:library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_arith.all;use ieee.std_logic_unsigned.all;实体说明:entity sellor isport ( clk:in std_logic; --系统时钟sel,cancel,reset: in std_logic; --选择、取消、开始(用于进入初始状态)变量定义:coin: in std_logic_vector(1 downto 0); --5角硬币、1元硬币crash:in std_logic_vector(5 downto 0); --100元、50元、20元、10元、5元、一元纸币item: in std_logic_vector(3 downto 0); --3种报纸quantity:in std_logic_vector(1 downto 0); --报纸数量(一次最多购买3件)change_out :out std_logic_vector(10 downto 0); --找零item_out :out std_logic_vector(3 downto 0); --是否购买了报纸(1表示有报纸出来、0表示没有报纸出来)change :out std_logic ); --是否有找零end sellor;结构体说明:architecture behave of sellor issignal price:std_logic_vector(7 downto 0);signal counter: std_logic_vector(10 downto 0); --币数计数器signal total_price:std_logic_vector(10 downto 0); --控制系统的时钟信号type state_type is (initial_state,item1_state,quantity_state,money_state,sell_state,change_state);signal state:state_type;signal temp:std_logic_vector(1 downto 0);signal quan:std_logic_vector(3 downto 0);begincom:process(reset,sel,clk)beginif (clk'event and clk='1')thenif reset='1' then state<=initial_state;temp<="00";quan<="0000";end if;case state iswhen initial_state=>item_out<="0000"; --出票口关闭change_out<="00000000000"; --找零口关闭total_price<="00000000000"; --票价总额记录清零counter<="00000000000";--投入钱币总额记录清零change<='0';state<=item1_state; 设定initial_state选择物品程序:when item1_state=>if temp<"11" thenelse state<=money_state;end if;when quantity_state=>if(cancel='1')then --按下“取消”按钮state<=initial_state;else 取消操作程序if quantity="00" thenitem_out<="0000";change<='0';change_out<="00000000000";state<=initial_state;else 当选择0个报纸total_price<=total_price+price*quantity;temp<=temp+1;quan<=quan+quantity;if (sel='1') then state<=item1_state;elsestate<=money_state;end if;end if;end if;货币识别:when money_state=>if(cancel='1')then --按下“取消”按钮state<=initial_state;end if;case crash is --纸币识别end case;case coin is --硬币识别end case;if counter>=total_price thenstate<=sell_state;--系统进入出票状态end if;购物操作程序:when sell_state =>if(cancel='1')thenitem_out<="0000";change<='1';change_out<=counter; --按下“取消”按钮state<=initial_state;elseif counter>=total_price thenitem_out<=quan; --判断是否还有找零state<=change_state; --系统进入找零状态elseitem_out<="0000";state<=initial_state;end if;end if;when change_state=>if(cancel='1')thenitem_out<="0000";change<='1';change_out<=counter; --按下“取消”按钮state<=initial_state;elseif counter>total_price thenchange<='1';change_out<=counter-total_price;item_out<=quan;elsechange<='0';change_out<="00000000000";state<=initial_state;end if;end if;end case;end if;end process;end behave;四、仿真波形自动售报机设计学校:铜仁学院系别:物电系班级:09级应用物理姓名:李志军学号:2009053011指导老师:冉耀宗2012年6月。

基于VHDL编程FPGA的地铁自动售票机

基于VHDL编程FPGA的地铁自动售票机

地铁自动售票机一、设计要求1、功能描述用于模仿地铁售票自动售票,完成地铁售票的核心控制功能。

2、功能要求售票机有两个进币孔,一个是输入硬币,识别的范围是一元硬币;一个是纸币,识别的范围是一元、两元、五元、十元、二十元。

乘客可以连续多次投入钱币。

乘客一次只能选择一个出站口,购买车票时,乘客先选出站口,有六个出站口可供选择,再选择所需的票数,然后投币,投入的钱币达到或者超过所需金额时,售票机自动出票,并找零。

本次交易结束后,等待下一次交易。

在选择出站口、所需票数以及在投币期间,乘客可以按取消键取消操作,钱币自动退出。

二、实验分析1、买票时,乘客按下开始键,售票机进入站台选择程序,乘客选择出站口后,可以按取消键重新选择,否则售票机自动进入票数选择程序,同样这时可以按下取消键重新开始选择出站口以及票数。

2、当选择好出站口以及所需票数时,乘客可以投硬币或者用纸币,当所投的钱币总额大于或者等于票价时,售票机自动出票以及找零。

期间,可以按下取消键重新开始选择,并退出所有的钱币。

3、乘客若还没选择出站口或者票数,就投币或者使用纸币,售票机会自动退出所有的钱币。

4、有六个站台可供乘客选择,每个乘客最多可以买3张票,六个站台编号为1到6,票价从2元依次递增到7。

三、系统流程图四、程序源代码LIBRARY IEEE;USE IEEE.std_logic_1164.ALL;USE IEEE.std_logic_arith.ALL;USE IEEE.std_logic_unsigned.ALL;ENTITY metrosell ISPORT(clk:in std_logic; --set the clock signalstartselect:in std_logic; --start to select the platformsure:in std_logic; --this button is to save your forward step(s)coin1y:in std_logic; --1 yuan coinpmoney1y:in std_logic; --1 yuan paper moneypmoney2y:in std_logic; --2 yuan paper moneypmoney5y:in std_logic; --5 yuan paper moneypmoney10y:in std_logic; --10 yuan paper moneypmoney20y:in std_logic; --20 yuan paper moneycancel:in std_logic; --cancel the forward step(s)number:in std_logic_vector(3 downto 0); --choose the number of the ticketsplatform:in std_logic_vector(3 downto 0); --choose the platform you want to reachmoneystorage:out std_logic; --to store the moneyacceptmo:out std_logic; --accept the moneystamp:out std_logic; --stamp outgatecharge:out std_logic_vector(3 downto 0); --the mount of charge,up to 15 yuanchargegate:out std_logic --charge outgate);END metrosell;ARCHITECTURE sell OF metrosell IStype state_type is(initial_type,selectp_type,selectnum_type,insert_type,stamp_type,charge_type);--define six typessignal state:state_type; --define a shared state BEGINmain:process(clk,state,startselect,platform,number,coin1y,pmoney1y,pmoney2y,pmon ey5y,pmoney10y,pmoney20y,cancel,sure)variable univalence :integer range 0 to 7; --the univalence of the ticket variable total_money :integer range 0 to 21; --the price of the ticket(s)variable selectp_alr:std_logic; --the flag of select platform typevariable selectnum_alr:std_logic; --the flag of select number typevariable stamp_alr:std_logic; --the flag of the stamp gate variable charge_alr:std_logic; --the flag of the charge gatevariable money_reg:integer range 0 to 21; --the mount of money put in variable coin1y_f:std_logic; --the flag of one yuan coin variable pmoney1y_f:std_logic; --the flag of one yuan paper moneyvariable pmoney2y_f:std_logic; --the flag of two yuan paper moneyvariable pmoney10y_f:std_logic; --the flag of ten yuan paper moneyvariable pmoney20y_f:std_logic; --the flag of twelve yuan paper moneyvariable pmoney5y_f:std_logic; --the flag of five yuan paper moneyvariable charge_reg:integer range 0 to 15; --the register of chargebeginif(rising_edge(clk)) thencase state iswhen initial_type => --initialize some variablesunivalence:=0;selectp_alr:='0';selectnum_alr:='0';stamp_alr:='0';charge_alr:='0';money_reg:=0;total_money:=0;coin1y_f:='0';pmoney1y_f:='0';pmoney2y_f:='0';pmoney5y_f:='0';pmoney10y_f:='0';pmoney20y_f:='0';moneystorage<='0';stamp<='0';charge_reg:=0;charge<="0000";acceptmo<='0';chargegate<='0';if (startselect='1') thenstate<=selectp_type;end if;when selectp_type =>if(selectp_alr='0'and cancel='0') then --choose the platform if(platform="0001")then univalence:=2;selectp_alr:='1';elsif(platform="0010")then univalence:=3;selectp_alr:='1';elsif(platform="0011")then univalence:=4;selectp_alr:='1';elsif(platform="0100")then univalence:=5;selectp_alr:='1';elsif(platform="0101")then univalence:=6;selectp_alr:='1';elsif(platform="0110")then univalence:=7;selectp_alr:='1';elsif(platform="0000")then univalence:=0;selectp_alr:='0';else null;end if;elsif(selectp_alr='1'and cancel='1')then state<=initial_type;elsif(selectp_alr='1'and sure='1') then state<=selectnum_type;end if;when selectnum_type => --you can buy at most 3 ticketsif(selectnum_alr='0'and cancel='0')then--choose the number of ticketsif(number="0001")thenif(univalence=2)thentotal_money:=2;selectnum_alr:='1';elsif(univalence=3)thentotal_money:=3;selectnum_alr:='1';elsif(univalence=4)thentotal_money:=4;selectnum_alr:='1';elsif(univalence=5)thentotal_money:=5;selectnum_alr:='1';elsif(univalence=6)thentotal_money:=6;selectnum_alr:='1';elsif(univalence=7)thentotal_money:=7;selectnum_alr:='1';elsif(univalence=0)thentotal_money:=0;selectnum_alr:='0';else null;end if;end if;if(number="0010")thenif(univalence=2)thentotal_money:=4;selectnum_alr:='1';elsif(univalence=3)thentotal_money:=6;selectnum_alr:='1';elsif(univalence=4)then total_money:=8;selectnum_alr:='1';elsif(univalence=5)then total_money:=10;selectnum_alr:='1';elsif(univalence=6)then total_money:=12;selectnum_alr:='1';elsif(univalence=7)then total_money:=14;selectnum_alr:='1';elsif(univalence=0)then total_money:=0;selectnum_alr:='0';else null;end if;end if;if(number="0011")thenif(univalence=2)then total_money:=6;selectnum_alr:='1';elsif(univalence=3)then total_money:=9;selectnum_alr:='1';elsif(univalence=4)then total_money:=12;selectnum_alr:='1';elsif(univalence=5)then total_money:=15;selectnum_alr:='1';elsif(univalence=6)then total_money:=18;selectnum_alr:='1';elsif(univalence=7)then total_money:=21;selectnum_alr:='1';elsif(univalence=0)then total_money:=0;selectnum_alr:='0';else null;end if;end if;elsif(selectnum_alr='1'and cancel='1')then state<=initial_type;elsif(selectnum_alr='1'and sure='1') then state<=insert_type;end if;when insert_type =>moneystorage<='1';if(money_reg<total_money and cancel='0')then--receive the inserted moneyif(coin1y='1'andcoin1y_f='0')then money_reg:=money_reg+1;coin1y_f:='1';end if;if(coin1y='0'and coin1y_f='1')then coin1y_f:='0';end if;if(pmoney1y='1'and pmoney1y_f='0')thenmoney_reg:=money_reg+1;pmoney1y_f:='1';end if;if(pmoney1y='0'and pmoney1y_f='1')thenpmoney1y_f:='0';end if;if(pmoney2y='1'and pmoney2y_f='0')thenmoney_reg:=money_reg+2;pmoney2y_f:='1';end if;if(pmoney2y='0'and pmoney2y_f='1')thenpmoney2y_f:='0';end if;if(pmoney5y='1'and pmoney5y_f='0')thenmoney_reg:=money_reg+5;pmoney5y_f:='1';end if;if(pmoney5y='0'and pmoney5y_f='1')thenpmoney5y_f:='0';end if;if(pmoney10y='1'and pmoney10y_f='0')thenmoney_reg:=money_reg+10;pmoney10y_f:='1';end if;if(pmoney10y='0'and pmoney10y_f='1')then pmoney10y_f:='0';end if;if(pmoney20y='1'and pmoney20y_f='0')then money_reg:=money_reg+20;pmoney20y_f:='1';end if;if(pmoney20y='0'and pmoney20y_f='1')then pmoney20y_f:='0';end if;elsif(money_reg<total_money and cancel='1')thenstate<=initial_type;elsif(money_reg>=total_money) then state<=stamp_type;end if;when stamp_type => --put out the stampif(stamp_alr='0')thenacceptmo<='1';stamp<='1';stamp_alr:='1';else state<=charge_type;end if;when charge_type => --put out the chargecharge_reg:=money_reg - total_money;case charge_reg iswhen 0 => charge<="0000";when 1 => charge<="0001";when 2 => charge<="0010";when 3 => charge<="0011";when 4 => charge<="0100";when 5 => charge<="0101";when 6 => charge<="0110";when 7 => charge<="0111";when 8 => charge<="1000";when 9 => charge<="1001";when 10 => charge<="1010";when 11 => charge<="1011";when 12 => charge<="1100";when 13 => charge<="1101";when 14 => charge<="1110";when 15 => charge<="1111";when others => charge<="0000";end case;if(charge_reg>0 and charge_alr='0') thenchargegate<='1';charge_alr:='1';elsif(charge_reg=0 and charge_alr='0')thenchargegate<='0';charge_alr:='1';else state<=initial_type;end if;end case;end if;end process main;END sell;五、波形仿真1、乘客按下开始按钮,进入选站台模式,选择二号站台,按下确定键,再选择票数为2张,按下确定键,售票机钱箱关闭,投入一张两元和五元纸币(对顺序没有要求),此时钱币总额大于票价,出两张票并找零一元。

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

自动售货机界面操作及显示VHDL语

目录
1摘要...1 2.正文...1 2.1系统设计...1 2.2单元电路设计...1 2.3软件设计...1 2.4系统测试...2 3.结论...4 4.经验体会 (4)
参考文献 (4)
附录A:系统电路原理图及引脚锁定图 (5)
附录B:程序设计的源代码 (6)
摘要
自动售货机是根据投入的钱币自动付货的机器,是一种全新的商业零售形式。

本论文主要介绍了VHDL的特点和应用;以自动售货机的设计为例,详细说明了其实现过程,并给出了实现代码和时序仿真波形。

主要创新点是可以实现多种商品的选择(这里是四种),而且价格和数量都是可调的;并可显示机器内商品剩余数量。

关键词:电子设计自动化;超高速集成电路硬件描述语言;自动售货机
正文
2.1.系统设计
设计一台自动售货机,要求具备货物信息存储、进程控制、硬币处理、余额计算、自动找零、状态显示等功能。

预先设定该自动售货机可自动出售4种不同的商品,基本货币单位为1元。

2.2.单元电路设计
分析系统设计要求,不然得知自动售货机系统可以通过多进程设计的方法
实现。

其中,最主要也是最核心的进程控制自动售货机的货物信息储备、购买、价格计算、找币等功能,其他进程则负责选择商品种类、消费品种单价和剩余
数量、消费余额的显示译码等。

自动售货机的系统框图如下图所示:
其中,clk为输入时钟脉冲信号,set为货物信息存储信号,get为购买信号,sel为货物品种选择信号,finish为购买完成信号,coin为1元的投币,price[3.0]和quantity[3.0]分别为商品的价格和剩余数量。

输出信号中,item[3.0]为商品种类并译码输出,act[3.0]为提示是否可购买的译码输出,y0[3.0]、y1[3.0]、y3[3.0]分别为商品的单价译码输出、剩余商品的数量显示、投币的硬币数量。

2.3.软件设计(如果用到软件要写)
设计平台:QuartusII 7.2
自动售货机的工作流程如下:
当置数信号set为高电平时,对商品的单价、数量进行相应的设置;在每
一次购买前,先对投入的硬币数量进行清零;购买时,首先以1元为基本单位
对投入的硬币数量进行计数并在数码管上进行显示;当选择信号sel高电平有
效时,选择所要购买的商品种类;当get信号高电平有效时,购买所选择的商品;当finish信号高电平有效时,结束交易并完成找币操作;当get信号为低电平是,则显示商品的单价及其剩余数量和剩余的钱数。

系统流程方框图如下所示:
开始
初始化
各项要求的设置以及set设置为高电平
投币
2.4.系统测试
总的仿真波形图如下所示:
部分图:
自动售货机的商品选择功能仿真图如上所示。

当商品选择信号sel为高电
平时,对要购买的商品种类进行选择。

每个时钟周期的上升沿都对商品对应的
编号进行加1操作,从而实现4种商品的循环选择。

投币及购买和找币功能如上图所示,当coin1为高电平时,每来一个上升
沿就表示投入1元,当get为高电平时,则说明对选择的商品种类进行购买,
计算剩余的商品数量和钱数;当购买完成信号finish为高电平是,根据计算得到的钱数给出应找的硬币数量,并显示余额和商品的剩余数量。

系统的性能参数:
3.结论
虽然VHDL的语法规则与其他计算机高级语言如C语言在很多方面很类似,但它毕竟是硬件描述语言,其本质作用在于描述硬件,因而会受到硬件环境的
限制。

因此,为了达到设计的预期效果,在代码编写前,应做到对硬件电路心
中有数,不能一味地追求代码的完美,而应该以实现的硬件电路的性能优劣为
标准。

通过对仿真结果进行详细分析可以看出,本篇设计的自动售货机功能正确,符合系统设计的要求。

4.经验体会
通过本次设计,让我更加熟练掌握多进程控制的方法,并能够在数字系统
设计中巧妙地应用多进程控制技术来取代若干模块之间的例化和级联。

参考文献:
[1]刘欲晓等.EDA技术与VHDL--
---电路开发应用实践[M].北京:电子工业出版社,2009.
[2]潘松等.EDA技术与VHDL(第2版)[M].北京:清华大学出版社,2008. 附录A:系统电路原理总图以及引脚锁定
系统电路原理总图:
引脚锁定图:
附录B:程序设计的源代码
源程序:
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;--系统时钟
set,get,sel,finish:in std_logic;--设定、买、选择、完成信号
coin1:in std_logic;--1元硬币
price,quantity:in std_logic_vector(3 downto 0);--价格、数量数据item0,act:out std_logic_vector(3 downto 0);--显示、开关信号
y0,y1,y3:out std_logic_vector(3 downto 0));
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;--定义RAM signal item:std_logic_vector(1 downto 0);--商品种类
signal coin:std_logic_vector(3 downto 0);--币数计数器
signal pri,qua:std_logic_vector(3 downto 0);--商品单价、数量
begin com:process(set,clk)
variable quan:std_logic_vector(3 downto 0);
begin if set='1'then ram(conv_integer(item))=price&quantity;
act="0000";
--把商品的单价、数量置入到RAM elsif clk'event and clk='1'then
y1=coin;
if coin1='1'then if coin"1001"then coin=coin+1;y1=coin;
act="0000";--投入1元硬币,coin自加1 else coin="0000";act="0001";
end if;
elsif sel='1'then item=item+1;--对商品进行循环选择
elsif get='1'then--对商品进行购买
if qua"0000"and coin=pri then coin=coin-pri;quan:=quan-1;--
act="0000";
ram(conv_integer(item))=pri&quan;
else act="0001";
end if;
elsif finish='1'then act="0000";--结束交易,退币(找币)
if coin"0001"then y1=coin;--此IF语句完成找币操作
end if;
elsif get='0'then act="0000";
for iin 4to 7loop pri(i-4)=ram(conv_integer(item))(i);--商品单价的读取
end loop;
for iin 0to 3loop quan(i):=ram(conv_integer(item))(i);--商品数量的读取
end loop;
end if;
end if;
qua=quan;
end process com;
code0:process(item)--商品指示灯译码
begin case item is when"00"=item0="0001";
when"01"=item0="0010";
when"10"=item0="0011";
when others=item0="0100";
end case;
end process;
code2:process(qua)--单价的BCD到七段码的译码begin y3=qua;
end process;
code3:process(pri)--
begin y0=pri;
end process;
end behav;。

相关文档
最新文档