基于VHDL编程FPGA的地铁自动售票机_第1页
基于VHDL编程FPGA的地铁自动售票机_第2页
基于VHDL编程FPGA的地铁自动售票机_第3页
基于VHDL编程FPGA的地铁自动售票机_第4页
基于VHDL编程FPGA的地铁自动售票机_第5页
已阅读5页,还剩7页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、地铁自动售票机一、设计要求1、功能描述用于模仿地铁售票自动售票,完成地铁售票的核心控制功能。2、功能要求 售票机有两个进币孔,一个是输入硬币,识别的范围是一元硬币;一个是纸币,识别的范围是一元、两元、五元、十元、二十元。乘客可以连续多次投入钱币。乘客 一次只能选择一个出站口,购买车票时,乘客先选出站口,有六个出站口可供选择,再选择所需的票数,然后投币,投入的钱币达到或者超过所需金额时,售票机自 动出票,并找零。本次交易结束后,等待下一次交易。在选择出站口、所需票数以及在投币期间,乘客可以按取消键取消操作,钱币自动退出。二、实验分析1、 买票时,乘客按下开始键,售票机进入站台选择程序,乘客选择出

2、站口后,可以按取消键重新选择,否则售票机自动进入票数选择程序,同样这时可以按下取消键重新开始选择出站口以及票数。2、 当选择好出站口以及所需票数时,乘客可以投硬币或者用纸币,当所投的钱币总额大于或者等于票价时,售票机自动出票以及找零。期间,可以按下取消键重新开始选择,并退出所有的钱币。3、 乘客若还没选择出站口或者票数,就投币或者使用纸币,售票机会自动退出所有的钱币。4、 有六个站台可供乘客选择,每个乘客最多可以买3张票,六个站台编号为1到6,票价从2元依次递增到7。三、系统流程图四、程序源代码LIBRARY IEEE;USE IEEE.std_logic_1164.ALL;USE IEEE.

3、std_logic_arith.ALL;USE IEEE.std_logic_unsigned.ALL;ENTITY metrosell IS PORT( clk:in std_logic; -set the clock signal startselect:in std_logic; -start to select the platform sure:in std_logic; -this button is to save your forward step(s) coin1y:in std_logic; -1 yuan coin pmoney1y:in std_logic; -1 yu

4、an paper money pmoney2y:in std_logic; -2 yuan paper money pmoney5y:in std_logic; -5 yuan paper money pmoney10y:in std_logic; -10 yuan paper money pmoney20y:in std_logic; -20 yuan paper money cancel:in std_logic; -cancel the forward step(s) number:in std_logic_vector(3 downto 0); -choose the number o

5、f the tickets platform:in std_logic_vector(3 downto 0); -choose the platform you want to reach moneystorage:out std_logic; -to store the money acceptmo:out std_logic; -accept the money stamp:out std_logic; -stamp outgate charge:out std_logic_vector(3 downto 0); -the mount of charge,up to 15 yuan cha

6、rgegate:out std_logic -charge outgate );END metrosell;ARCHITECTURE sell OF metrosell IS type state_type is (initial_type,selectp_type,selectnum_type,insert_type,stamp_type,charge_type); -define six types signal state:state_type; -define a shared stateBEGINmain:process(clk,state,startselect,platform,

7、number,coin1y,pmoney1y,pmoney2y,pmoney5y,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 type variable selec

8、tnum_alr:std_logic; -the flag of select number type variable stamp_alr:std_logic; -the flag of the stamp gate variable charge_alr:std_logic; -the flag of the charge gate variable money_reg:integer range 0 to 21; -the mount of money put in variable coin1y_f:std_logic; -the flag of one yuan coin varia

9、ble pmoney1y_f:std_logic; -the flag of one yuan paper money variable pmoney2y_f:std_logic; -the flag of two yuan paper money variable pmoney10y_f:std_logic; -the flag of ten yuan paper money variable pmoney20y_f:std_logic; -the flag of twelve yuan paper money variable pmoney5y_f:std_logic; -the flag

10、 of five yuan paper money variable charge_reg:integer range 0 to 15; -the register of charge begin if(rising_edge(clk) then case state is when initial_type = -initialize some variables univalence:=0; selectp_alr:=0; selectnum_alr:=0; stamp_alr:=0; charge_alr:=0; money_reg:=0; total_money:=0; coin1y_

11、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) then state if(selectp_alr=0and cancel=0) then -choose the platform if(platform=0001)then univalence:=2;selectp_alr:=1;

12、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

13、univalence:=0;selectp_alr:=0; else null; end if; elsif(selectp_alr=1and cancel=1)then state=initial_type; elsif(selectp_alr=1and sure=1) then state -you can buy at most 3 tickets if(selectnum_alr=0and cancel=0)then-choose the number of tickets if(number=0001)then if(univalence=2)then total_money:=2;

14、selectnum_alr:=1; elsif(univalence=3)then total_money:=3;selectnum_alr:=1; elsif(univalence=4)then total_money:=4;selectnum_alr:=1; elsif(univalence=5)then total_money:=5;selectnum_alr:=1; elsif(univalence=6)then total_money:=6;selectnum_alr:=1; elsif(univalence=7)then total_money:=7;selectnum_alr:=

15、1; elsif(univalence=0)then total_money:=0;selectnum_alr:=0; else null; end if; end if; if(number=0010)then if(univalence=2)then total_money:=4;selectnum_alr:=1; elsif(univalence=3)then total_money:=6;selectnum_alr:=1; elsif(univalence=4)then total_money:=8;selectnum_alr:=1; elsif(univalence=5)then t

16、otal_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)then if(univalence=2)then total_money:=6;selectnum_a

17、lr:=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; elsi

18、f(univalence=0)then total_money:=0;selectnum_alr:=0; else null; end if; end if; elsif(selectnum_alr=1and cancel=1)then state=initial_type; elsif(selectnum_alr=1and sure=1) then state moneystorage=1; if(money_regtotal_money and cancel=0)then-receive the inserted money if(coin1y=1and coin1y_f=0)then m

19、oney_reg:=money_reg+1;coin1y_f:=1;end if; if(coin1y=0and coin1y_f=1)then coin1y_f:=0;end if; if(pmoney1y=1and pmoney1y_f=0)then money_reg:=money_reg+1;pmoney1y_f:=1;end if; if(pmoney1y=0and pmoney1y_f=1)then pmoney1y_f:=0;end if; if(pmoney2y=1and pmoney2y_f=0)then money_reg:=money_reg+2;pmoney2y_f:=

20、1;end if; if(pmoney2y=0and pmoney2y_f=1)then pmoney2y_f:=0;end if; if(pmoney5y=1and pmoney5y_f=0)then money_reg:=money_reg+5;pmoney5y_f:=1;end if; if(pmoney5y=0and pmoney5y_f=1)then pmoney5y_f:=0;end if; if(pmoney10y=1and pmoney10y_f=0)then money_reg:=money_reg+10;pmoney10y_f:=1; end if; if(pmoney10

21、y=0and pmoney10y_f=1)then pmoney10y_f:=0;end if; if(pmoney20y=1and pmoney20y_f=0)then money_reg:=money_reg+20;pmoney20y_f:=1; end if; if(pmoney20y=0and pmoney20y_f=1)then pmoney20y_f:=0;end if; elsif(money_regtotal_money and cancel=1)then state=total_money) then state -put out the stamp if(stamp_alr

22、=0)then acceptmo=1; stamp=1; stamp_alr:=1; else state -put out the charge charge_reg:=money_reg - total_money; case charge_reg is when 0 = charge charge charge charge charge charge charge charge charge charge charge charge charge charge charge charge charge0 and charge_alr=0) then chargegate=1; charge_alr:=1; elsif(charge_reg=0 and charge_alr=0)then chargegate=0; charge_alr:=1; else state=ini

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论