library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity sellpencil is port( cp,en: in std_logic; price:in std_logic_vector(3 downto 0); coin1,coin5,coin10:in std_logic; get,finish: in std_logic; cur_m:buffer std_logic_vector(3 downto 0); cur_money:buffer std_logic_vector(3 downto 0); ya_out,yb_out,yc_out,yd_out:out std_logic); end sellpencil; architecture be_sellpencil of sellpencil is begin process(cp,en) begin if en='0' then ya_out<='0';yb_out<='0';yc_out<='0';yd_out<='0';cur_m<="0000"; end if; if(cp'event and cp='1' and en='1' and finish='0')then if coin1='1' then if cur_money<"1111"then cur_money<=cur_money+"0001"; else cur_money<="0000"; end if; elsif coin5='1' then if cur_money<"1111"then cur_money<=cur_money+"0101"; else cur_money<="0000"; end if; elsif coin10='1' then if cur_money<"1111"then cur_money<=cur_money+"1010"; else cur_money<="0000"; end if; end if; end if; if get='1' and finish='1' then if cur_money>=price then if price="0110" then ya_out<='1';cur_m<=cur_money-price; elsif price="0111" then yb_out<='1';cur_m<=cur_money-price; elsif price="1000" then yc_out<='1';cur_m<=cur_money-price; elsif price="1001" then yd_out<='1';cur_m<=cur_money-price; end if; else ya_out<='0';yb_out<='0';yc_out<='0';yd_out<='0';cur_m<=cur_money; end if; end if; end process; end be_sellpencil;