E

#### Esma

##### Guest

library ieee;

use ieee.std_logic_1164.all;

entity vending_machine is

port (

CLK, RESET: in std_logic;

N, D: in std_logic;

output: out std_logic;

change: out std_logic_vector(5 downto 0)

);

end vending_machine;

architecture process_3 of vending_machine is

type state_type is (s0, s1, s2, s3, s4, s5, s6, s7, s8, s9);

signal state, next_state: state_type;

begin

process (CLK, RESET)

begin

if (RESET = \'1\') then

state <= s0;

elsif (rising_edge(CLK)) then

state <= next_state;

end if;

end process;

process (state, N, D)

begin

case state is

when s0 =>

if N = \'0\' and D = \'0\' then

next_state <= s0;

output <= \'0\';

change <= \"000000\";

elsif N = \'0\' and D = \'1\' then

next_state <= s1;

output <= \'0\';

change <= \"000000\";

elsif N = \'1\' and D = \'0\' then

next_state <= s2;

output <= \'0\';

change <= \"000000\";

end if;

when s1 =>

if N = \'0\' and D = \'0\' then

next_state <= s0;

output <= \'0\';

change <= \"000101\";

elsif N = \'0\' and D = \'1\' then

next_state <= s2;

output <= \'0\';

change <= \"000000\";

elsif N = \'1\' and D = \'0\' then

next_state <= s3;

output <= \'0\';

change <= \"000000\";

end if;

when s2 =>

if N = \'0\' and D = \'0\' then

next_state <= s0;

output <= \'0\';

change <= \"001010\";

elsif N = \'0\' and D = \'1\' then

next_state <= s3;

output <= \'0\';

change <= \"000000\";

elsif N = \'1\' and D = \'0\' then

next_state <= s4;

output <= \'0\';

change <= \"000000\";

end if;

when s3 =>

if N = \'0\' and D = \'0\' then

next_state <= s0;

output <= \'0\';

change <= \"001111\";

elsif N = \'0\' and D = \'1\' then

next_state <= s4;

output <= \'0\';

change <= \"000000\";

elsif N = \'1\' and D = \'0\' then

next_state <= s5;

output <= \'0\';

change <= \"000000\";

end if;

when s4 =>

if N = \'0\' and D = \'0\' then

next_state <= s0;

output <= \'0\';

change <= \"010100\";

elsif N = \'0\' and D = \'1\' then

next_state <= s5;

output <= \'0\';

change <= \"000000\";

elsif N = \'1\' and D = \'0\' then

next_state <= s6;

output <= \'0\';

change <= \"000000\";

end if;

when s5 =>

if N = \'0\' and D = \'0\' then

next_state <= s0;

output <= \'0\';

change <= \"011001\";

elsif N = \'0\' and D = \'1\' then

next_state <= s6;

output <= \'0\';

change <= \"000000\";

elsif N = \'1\' and D = \'0\' then

next_state <= s7;

output <= \'0\';

change <= \"000000\";

end if;

when s6 =>

if N = \'0\' and D = \'0\' then

next_state <= s0;

output <= \'0\';

change <= \"011110\";

elsif N = \'0\' and D = \'1\' then

next_state <= s7;

output <= \'0\';

change <= \"000000\";

elsif N = \'1\' and D = \'0\' then

if RESET = \'1\' then

next_state <= s0;

output <= \'1\';

change <= \"000000\";

else

next_state <= s8;

output <= \'1\';

change <= \"000000\";

end if;

end if;

when s7 =>

if N = \'0\' and D = \'0\' then

next_state <= s0;

output <= \'0\';

change <= \"100011\";

elsif N = \'0\' and D = \'1\' then

if RESET = \'1\' then

next_state <= s0;

output <= \'1\';

change <= \"000101\";

else

next_state <= s9;

output <= \'1\';

change <= \"000101\";

end if;

elsif N = \'1\' and D = \'0\' then

if RESET = \'1\' then

next_state <= s0;

output <= \'1\';

change <= \"000000\";

else

next_state <= s9;

output <= \'1\';

change <= \"000000\";

end if;

end if;

when s8 =>

if N = \'0\' and D = \'0\' then

if RESET = \'1\' then

next_state <= s0;

output <= \'1\';

change <= \"000000\";

else

next_state <= s8;

output <= \'1\';

change <= \"000000\";

end if;

end if;

when s9 =>

if RESET = \'1\' then

next_state <= s0;

output <= \'1\';

change <= \"000101\";

else

next_state <= s9;

output <= \'0\';

change <= \"000000\";

end if;

when others =>

next_state <= s0;

output <= \'0\';

change <= \"000000\";

end case;

end process;

end architecture process_3;