简易地铁自动售票系统.docx
《简易地铁自动售票系统.docx》由会员分享,可在线阅读,更多相关《简易地铁自动售票系统.docx(22页珍藏版)》请在冰豆网上搜索。
![简易地铁自动售票系统.docx](https://file1.bdocx.com/fileroot1/2023-1/23/5768ccef-08e6-4c87-a84e-3f2595575111/5768ccef-08e6-4c87-a84e-3f25955751111.gif)
简易地铁自动售票系统
数字电路与逻辑设计实验
实验报告
题目:
简易地铁自动售票系统
学院:
信息与通信工程学院
专业:
电子信息工程
一、设计课题的任务要求
基本要求:
a)地铁票价统一为每张两元,只能投入币值为五元的人民币进行购票。
b)能够开机自检,检验显示器件正常。
c)通过按键开关BTN输入购票张数和投入的人民币张数并恰当显示相应信息。
d)设置适当的声音提示或显示提示表示取票和找零。
e)一次购票成功后系统能够恰当地转入下一次购票等待状态。
f)系统能够复位。
提高要求:
将投币种类增加为1元、5元和10元三种。
二、系统设计
本次实验中采用的是自自顶向下的设计方法,即从整个系统功能出发,按一定原则将系统划分为若干子系统,再将每个子系统分为若干功能模块,再将每个模块分成若干较小的模块……直至分成许多基本模块实现。
1.外部呈现结构
CAT5,CAT4:
用数码管显示购票张数
CAT3,CAT2:
显示总共输入的钱数
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、波形分析
上面的波形只是仿真其中一个情况,顺序输入信息,中间没有按过取消,且输入钱数大于总票价,通过波形可以看出,购票成功且有找零,跟所预期吻合,说明仿真成功。
四、源程序
libraryieee;
useieee.std_logic_1164.all;
useieee.std_logic_unsigned.all;
entitysubwayis
port(clk:
instd_logic;
buy:
instd_logic;
yes:
instd_logic;
ok:
instd_logic;
start:
instd_logic;
no:
instd_logic;
count1:
instd_logic;
count2:
instd_logic;
count3:
instd_logic;
count0:
instd_logic;
f:
outstd_logic_vector(6downto0);
sell:
outstd_logic_vector(5downto0);
ticket_out:
outstd_logic_vector(2downto0);
change_out:
outstd_logic_vector(3downto0);
present_state:
outstd_logic;
a,b,c,d:
outstd_logic:
='0';
--count_2,count_3:
outstd_logic;
afford:
outstd_logic;
beep:
outstd_logic;
led:
outstd_logic_vector(7downto0)
);
endsubway;
architecturebehaveofsubwayis
typestate_typeis(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:
std_logic;
signaltmp1:
integerrange0to4999;
signaltmp2:
integerrange0to9999;
signalcount0temp,count1temp,count2temp,count3temp:
std_logic;
signalcount0tempp,count1tempp,count2tempp,count3tempp:
std_logic;
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
iftmp1=4999then
tmp1<=0;
else
tmp1<=tmp1+1;
endif;
endif;
endprocessp1;
p11:
process(clk)
begin
if(clk'eventandclk='1')then
iftmp2=9999then
tmp2<=0;
else
tmp2<=tmp2+1;--shumaguanshizhong
endif;
endif;
endprocessp11;
p2:
process(tmp1,tmp2)
begin
iftmp1=4999then
clk_out200<='1';
else
clk_out200<='0';
endif;
iftmp2=9999then
clk_out100<='1';
else
clk_out100<='0';
endif;
endprocessp2;
--process(clk)
--begin
--clk_out100<=clk;
--clk_out200<=clk;
--endprocess;
-----------------------------------------按键消抖---------------------------------------------------------------------
p3:
process(clk_out100,count1,count2,count3)
begin
IF(clk_out100'EVENTANDclk_out100='0')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);
ENDPROCESSp3;
-----------------------------------------------按键输入及计算-----------------------------------------------------------
process(clk_out100,count_1,count_2,count_3)
begin
IF(clk_out100'EVENTANDclk_out100='1')THEN
if(buy='1')then
ticket_count<="000";
total_money<="0000";
endif;
if(no='1')then
ticket_count<="000";
total_money<="0000";
endif;
if(count_0='1')then
a<='1';
ticket_count<=ticket_count+"001";
endif;
if(count_1='1')then
c<='1';
total_money<=total_money+"0001";
endif;
if(count_2='1')then
b<='1';
total_money<=total_money+"0101";
endif;
if(count_3='1')then
d<='1';
total_money<=total_money+"1010";
endif;
endif;
endprocess;
--------------------------------------------------各状态转换及输出-----------------------------------------------------
p4:
process(clk_out100,total_money,ticket_count)
variableflag:
std_logic;
variablesign:
std_logic:
='0';
variabletotal_price:
std_logic_vector(3downto0);
variabletemp:
std_logic_vector(3downto0);
variabletotal_money1:
std_logic_vector(3downto0);
variableticket_temp:
std_logic_vector(2downto0);
variablei,j,k:
integerrange0to9999;
begin
IF(clk_out100'EVENTANDclk_out100='1')THEN
casestateis
whenwaiting_state=>
led<="11111111";
present_state<='0';
flag:
='0';
temp:
="0000";
total_price:
="1011";
ticket_out<="001";
change_out<="0000";
present_state<='0';
i:
=0;
j:
=0;
k:
=0;
ticket_temp:
="000";
total_money1:
="0000";
if(yes='1')then
present_state<='1';
state<=select_state;
else
state<=waiting_state;
endif;
whenselect_state=>
led<="10000000";
caseticket_countis
when"001"=>
total_price:
="0010";
ticket_temp:
="001";
when"010"=>
total_price:
="0100";
ticket_temp:
="010";
when"011"=>
total_price:
="0110";
ticket_temp:
="011";
when"100"=>
total_price:
="1000";
ticket_temp:
="100";
when"101"=>
total_price:
="1010";
ticket_temp:
="101";
when"110"=>
total_price:
="1100";
ticket_temp:
="110";
when"111"=>
total_price:
="1110";
ticket_temp:
="111";
whenothers=>
state<=select_state;
endcase;
if(no='1')then
state<=waiting_state;
endif;
if(ok='1')then
led<="01000000";
state<=insert_state;
endif;
wheninsert_state=>
--led<="00001111";
total_money1:
=total_money;
if(no='1')then
state<=change_state;
flag:
='1';
endif;
if(start='1')then
if(total_price>total_money1)then
state<=change_state;
afford<='1';
else
state<=ticket_state;
endif;
endif;
whenticket_state=>
led<="00100100";
beep<='1';
if(i=9999)then
state<=change_state;
else
i:
=i+1;
ticket_out<=ticket_temp;
afford<='0';
endif;
whenchange_state=>
led<="10101010";
temp:
=total_money1-total_price;
if(flag='1')then
if(j=9999)then
state<=waiting_state;
else
j:
=j+1;
change_out<="1111";
endif;
elsif(temp="0000")then
state<=waiting_state;
else
if(k=9999)then
state<=waiting_state;
else
k:
=k+1;
change_out<="1111";
led<="10101010";
endif;
endif;
endcase;
endif;
endprocess;
------------------------------------------数码管扫描输出及译码------------------------------------------------
p5:
process(clk_out200,ticket_count,total_money)
variablei:
integerrange0to2;
variablej:
integerrange0to1;
begin
IF(clk_out200'EVENTANDclk_out200='1')THEN
if(i=0)then
i:
=i+1;
caseticket_countis
when"000"=>f<="0111111";sell<="101111";
when"001"=>f<="0000110";sell<="101111";
when"010"=>f<="1011011";sell<="101111";
when"011"=>f<="1001111";sell<="101111";
when"100"=>f<="1100110";sell<="101111";
when"101"=>f<="1101101";sell<="101111";
when"110"=>f<="1111101";sell<="101111";
when"111"=>f<="0000111";sell<="101111";
endcase;
else
i:
=0;
casetotal_moneyis
when"0000"=>
if(j=1)then
f<="0111111";sell<="111011";
j:
=0;
else
j:
=i+1;
f<="0111111";sell<="110111";
endif;
when"0001"=>
if(j=1)then
f<="0000110";sell<="111011";
j:
=0;
else
j:
=i+1;
f<="0111111";sell<="110111";
endif;
when"0010"=>
if(j=1)then
f<="1011011";sell<="111011";
j:
=0;
else
j:
=i+1;
f<="0111111";sell<="110111";
endif;
when"0011"=>
if(j=1)then
f<="1001111";sell<="111011";
j:
=0;
else
j:
=i+1;
f<="0111111";sell<="110111";
endif;
when"0100"=>
if(j=1)then
f<="1100110";sell<="111011";
j:
=0;
else
j:
=i+1;
f<="0111111";sell<="110111";
endif;
when"0101"=>
if(j=1)then
f<="1101101";sell<="111011";
j:
=0;
else
j:
=i+1;
f<="0111111";sell<="110111";
endif;
when"0110"=>
if(j=1)then
f<="1111101";sell<="111011";
j:
=0;
else
j:
=i+1;
f<="0111111";sell<="110111";
endif;
when"0111"=>
if(j=1)then
f<="0000111";sell<="111011";
j:
=0;
else
j:
=i+1;
f<="0111111";sell<="110111";
endif;
--whenothers=>null;
when"1000"=>
if(j=1)then
f<="1111111";sell<="111011";
j:
=0;
else
j:
=i+1;
f<="0111111";sell<="110111";
endif;
when"1001"=>
if(j=1)then
f<="1101111";sell<="111011";
j:
=0;
else
j:
=i+1;
f<="0111111";sell<="110111";
endif;
when"1010"=>
if(j=1)then
f<="0111111";sell<="111011";
j:
=0;
else
j:
=i+1;
f<="0000110";
sell<="110111";
endif;
when"1011"=>
if(j=1)then
f<="0000110";sell<="111011";
j:
=0;
else
j:
=i+1;
f<="0000110";sell<="110111";
endif;
when"1100"=>
if(j=1)then
f<="1011011";sell<="111011";
j:
=0;
else
j:
=i+1;
f<="0000110";sell<="110111";
endif;
when"1101"=>
if(j=1)then
f<="1001111";sell<="111011";
j:
=0;
else
j:
=i+1;
f<="0000110";sell<="110111";
endif;
when"1110"=>
if(j=1)then
f<="1100110";sell<="111011";
j:
=0;
else
j:
=i+1;
f<="0000110";sell<="110111";
endif;
when"1111"=>
if(j=1)then
f<="1101101";sell<="111011";
j:
=0;
else
j:
=i+1;
f<="0000110";sell<="110111";
endif;
endcase;
endif;
endif;
endprocess;
endbehave;
五、功能说明
设计系统时,是按照实验要求所做的,对照实验要求,完成的功能有:
开机即自检,检验显示器件正常;可以输入1元,5元,10元的纸币,通过按键开关BTN输入购票张数和投入的人民币总额并在数码管上显示并需在按下相应按键进行确认;设置数码管亮灭表示取票和找零以及各状态,其中出票与找零状态是自动跳转至下一状态;一次购票成功后系统能够恰当地转入下一次购票等待状态;系统能够在任意状态复