资源描述:
《地铁售票模拟系统.doc》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、地铁售票模拟系统introduction:对投入的纸币和硬币进行识别;可以选择站点;有两类票种;可以找钱;最多可选三张票;有中途取消购票功能;main:源程序代码:libraryieee;useieee.std_logic_1164.all;useieee.std_logic_unsigned.all;entityautosellisport(clk:instd_logic;--时钟信号reset:instd_logic;--复位信号coin5,coin10:instd_logic;--分别代表5角和1元的硬币信号p
2、aper1,paper2,paper5,paper10:instd_logic;--分别代表1元,2元,5元和10元的纸币信号other_money:instd_logic;--代表自动售票机不能识别的钱n1,n2,n3:instd_logic;--代表输入票数量信号ok,cancel:instd_logic;--代表确定,取消键station1,station2,station3,station4:instd_logic;--代表站点output1,output2,output3,output4:outstd_lo
3、gic;--代表票的输出孔attention:outstd_logic;--代表输出欠资信号mistake:outstd_logic;--代表投错钱币的信号no_choice:outstd_logic;--代表未选的信号repay:outstd_logic;--代表找钱信号repaymoney:outstd_logic_vector(6downto0)--找钱金额(5角的个数));endautosell;architectureherozhangshibeiofautosellistypestate_typeis(i
4、nput_state,--投币状态output_state,--输出状态cond_state--选择状态--charge_state--找钱状态);signalstate:state_type;signalcoin_in:std_logic;--有硬币输入signalpa_in:std_logic;--有纸币输入signalset_2,set_4:std_logic;--分别代表2元,4元的票--signalamount:std_logic_vector(6downto0);--投入的钱币总额--signalpric
5、e:std_logic_vector(6downto0);--所需的钱币总额begincoin_in<=coin5orcoin10orother_money;pa_in<=paper1orpaper2orpaper5orpaper10orother_money;process(clk,reset)variableamount:std_logic_vector(6downto0);--投入的钱币总额variableprice:std_logic_vector(6downto0);--所需的钱币总额beginif(res
6、et='1')then--复位amount:="0000000";price:="0000000";repaymoney<="0000000";state<=input_state;repay<='0';output1<='0';output2<='0';output3<='0';output4<='0';attention<='0';no_choice<='0';mistake<='0';elsif(rising_edge(clk))thencasestateiswheninput_state=>--计算所投入的金
7、额总值if(coin_in='1')thenif(coin5='1'andother_money='0')thenamount:=amount+"0000001";mistake<='0';endif;if(coin10='1'andother_money='0')thenamount:=amount+"0000010";mistake<='0';endif;if(other_money='1')thenmistake<='1';endif;elsenull;endif;if(pa_in='1')thenif(pap
8、er1='1'andother_money='0')thenamount:=amount+"0000010";mistake<='0';endif;if(paper2='1'andother_money='0')thenamount:=amount+"0000100";mistake<='0';endif;if(paper5='1'andoth