设计目标:实现收取5元和十元两种货币,共销售矿泉水和可乐两种饮料,售价分别为2元和4元。一共有3种状态,购买完饮料,应按下确认按钮,实现复位功能。状态图:投入5元状态s1初始s0状态s2投入10元状态s1、s2时实现输出饮料和找零。此售饮料系统一次只能购买一次,功能简单,较易实现。因为投入只有5元和10元两种情况,一次购买只有一瓶,所以找零只有4种情况,分别用ret="00","01","10","11"表示其逻辑。inp_1,inp_2分别表示投入5元和10元;outp="01","10"表示输出矿泉水和可乐两种饮料。实验程序:libraryieee;;entitysellingis port(clk,reset,inp_1,inp_2,price_1,price_2:instd_logic; outp,ret:outstd_logic_vector(1downto0));endentity;architecturebehavofsellingistypefsm_stis(s0,s1,s2);signalc_st,next_state:fsm_st;beginreg:process(clk,reset)beginifreset='0'thenc_st<=s0;elsifclk='1'andclk'eventthenc_st<=next_state;endif;:process(c_st,reset,inp_1,inp_2,price_1,price_2)begincasec_stiswhens0=> ifinp_1='1'thennext_state<=s1; elsenext_state<=s1;endif; ifinp_2='1'thennext_state<=s2; elsenext_state<=s0;endif; whens1=> ifprice_1='1'thenoutp<="01"; ret<="00"; next_state<=s0; elsenext_state<=s1;endif; ifprice_2='1'thenoutp<="10"; ret<="01"; next_state<=s0; elsenext_state<=s1;endif;whens2=> ifprice_1='1'thenoutp<="01"; ret<="10"; next_state<=s0; elsenext_state<=s2;endif; ifprice_2='1'thenoutp<="10"; ret<="11"; next_state<=s0; elsenext_state<=s2;endif;whenothers=>next_state<=s0;endcase;;endbehav;原理图: 撤磊属易挠厢礁墟该
EDA售饮料机 来自淘豆网m.daumloan.com转载请标明出处.