简易地铁自动售票系统Word文档下载推荐.docx
《简易地铁自动售票系统Word文档下载推荐.docx》由会员分享,可在线阅读,更多相关《简易地铁自动售票系统Word文档下载推荐.docx(21页珍藏版)》请在冰豆网上搜索。
![简易地铁自动售票系统Word文档下载推荐.docx](https://file1.bdocx.com/fileroot1/2022-10/20/535a6d4a-53c3-4cc5-8e89-d08f4673dabd/535a6d4a-53c3-4cc5-8e89-d08f4673dabd1.gif)
显示总共输入的钱数
BTN7:
开始购票按键
BTN6:
输入购票张数确定按键
BTN5:
输入钱数确定按键/确定购买按键
BTN4:
复位键/取消键
BTN3:
通过按键按下次数输入购票张数
BTN2:
每按下1次,输入1张1元纸币
BTN1:
每按下1次,输入1张5元纸币
BTN0:
每按下1次,输入1张10元纸币
LED7-0:
通过8个灯不同的亮灭显示不同的状态
全亮:
开机自检及复位状态
LED7亮:
输入购票张数状态
LED6亮:
输入总钱数状态
LED5,2亮:
显示购票成功
亮灭亮灭亮灭亮灭:
显示找零状态
2、模块划分及功能
1、计算模块:
计算用户投币的总金额,以及用户的余额。
2、显示模块:
将计算的结果及用户操作信号译码后显示在数码管或LED灯上。
3、输入模块:
通过按键,开关输入信息
4、信号模块:
系统对系统时钟,用户的买、选择、完成信号,显示
开关信号等信号的设置。
3、自动售货机系统总体框图
4、流程图
5、MSD图
S0:
waite_state
S1:
select_state
S2:
insert_state
S3:
ticket_state
S4:
change_state
三、仿真波形及波形分析
1、仿真波形
2、波形分析
上面的波形只是仿真其中一个情况,顺序输入信息,中间没有按过取消,且输入钱数大于总票价,通过波形可以看出,购票成功且有找零,跟所预期吻合,说明仿真成功。
四、源程序
library
ieee;
useieee.std_logic_1164.all;
useieee.std_logic_unsigned.all;
entity
subway
is
port(clk:
instd_logic;
buy:
instd_logic;
yes:
ok:
start:
no
:
count1:
count2:
count3:
count0:
f:
outstd_logic_vector(6downto0);
sell:
outstd_logic_vector(5downto0);
ticket_out
out
std_logic_vector(2downto0);
change_out
std_logic_vector(3
downto0);
present_state
std_logic;
a,b,c,d:
outstd_logic:
='
0'
;
--count_2,count_3:
outstd_logic;
afford:
beep:
outstd_logic;
led:
outstd_logic_vector(7downto0)
);
endsubway;
architecturebehaveofsubwayis
typestate_type
is(waiting_state,select_state,insert_state,ticket_state,change_state);
signalstate:
state_type;
signalclk_out100,clk_out200:
std_logic;
signalcount_0,count_1,count_2,count_3:
signaltmp1:
integerrange0to4999;
signaltmp2:
integerrange0to9999;
signalcount0temp,count1temp,count2temp,count3temp:
signalcount0tempp,count1tempp,count2tempp,count3tempp:
signalticket_count:
std_logic_vector(2downto0);
signaltotal_money:
std_logic_vector(3downto0);
begin
----------------------------------------------------------分频-------------------------------------------------------------
p1:
process(clk)
//2次分频,一次分为10Khz,一次分为5Khz,一个用于数码管扫描
begin
一个用于按键消抖
if(clk'
eventandclk='
1'
)then
if
tmp1=4999then
tmp1<
=0;
else
=tmp1+1;
endif;
endprocessp1;
p11:
process(clk)
begin
iftmp2=9999then
tmp2<
=tmp2+1;
--shumaguanshizhong
endprocessp11;
p2:
process(tmp1,tmp2)
iftmp1=4999then
clk_out200<
endif;
clk_out100<
else
endprocessp2;
--process(clk)
--begin
--clk_out100<
=clk;
--clk_out200<
--endprocess;
-----------------------------------------按键消抖---------------------------------------------------------------------
p3:
process(clk_out100,count1,count2,count3)
IF(clk_out100'
EVENTANDclk_out100='
)THEN
count1tempp<
=count1temp;
count1temp<
=count1;
count2tempp<
=count2temp;
count2temp<
=count2;
count3tempp<
=count3temp;
count3temp<
=count3;
count0tempp<
=count0temp;
count0temp<
=count0;
ENDIF;
count_1<
=clk_out100ANDcount1tempAND(NOTcount1tempp);
count_2<
=clk_out100ANDcount2tempAND(NOTcount2tempp);
count_3<
=clk_out100ANDcount3tempAND(NOTcount3tempp);
count_0<
=clk_out100ANDcount0tempAND(NOTcount0tempp);
ENDPROCESS
p3;
-----------------------------------------------按键输入及计算-----------------------------------------------------------
process(clk_out100,count_1,count_2,count_3)
if(buy='
ticket_count<
="
000"
total_money<
0000"
if(no='
if(count_0='
a<
=ticket_count+"
001"
if(count_1='
c<
=total_money+"
0001"
if(count_2='
b<
0101"
if(count_3='
d<
1010"
endprocess;
--------------------------------------------------各状态转换及输出-----------------------------------------------------
p4:
process(clk_out100,total_money,ticket_count)
variableflag:
variablesign:
std_logic:
variabletotal_price:
variabletemp:
variabletotal_money1:
variableticket_temp:
variable
i,j,k:
integer
range0to9999;
IF(clk_