my project designing a vending machine that sells a candy for 40 cent. it=accept olny 5 cent(N) and 10 cent (D). and the candy i wrote this code for=
library ieee;=20
use ieee.std_logic_1164.all;=20
=20
entity vending_machine is=20
port (=20
CLK, RESET: in std_logic;=20
N, D: in std_logic;=20
output: out std_logic;=20
change: out std_logic_vector(5 downto 0)=20
);=20
end vending_machine;=20
=20
architecture process_3 of vending_machine is=20
type state_type is (s0, s1, s2, s3, s4, s5, s6, s7, s8, s9);=20
signal state, next_state: state_type;=20
=20
begin=20
process (CLK, RESET)=20
begin=20
if (RESET =3D '1') then=20
state <=3D s0;=20
elsif (rising_edge(CLK)) then=20
state <=3D next_state;=20
end if;=20
end process;=20
=20
process (state, N, D)=20
begin=20
case state is=20
when s0 =3D>=20
if N =3D '0' and D =3D '0' then=20
next_state <=3D s0;=20
output <=3D '0';=20
change <=3D "000000";=20
elsif N =3D '0' and D =3D '1' then=20
next_state <=3D s1;=20
output <=3D '0';=20
change <=3D "000000";=20
elsif N =3D '1' and D =3D '0' then=20
next_state <=3D s2;=20
output <=3D '0';=20
change <=3D "000000";=20
end if;=20
=20
when s1 =3D>=20
if N =3D '0' and D =3D '0' then=20
next_state <=3D s0;=20
output <=3D '0';=20
change <=3D "000101";=20
elsif N =3D '0' and D =3D '1' then=20
next_state <=3D s2;=20
output <=3D '0';=20
change <=3D "000000";=20
elsif N =3D '1' and D =3D '0' then=20
next_state <=3D s3;=20
output <=3D '0';=20
change <=3D "000000";=20
end if;=20
=20
when s2 =3D>=20
if N =3D '0' and D =3D '0' then=20
next_state <=3D s0;=20
output <=3D '0';=20
change <=3D "001010";=20
elsif N =3D '0' and D =3D '1' then=20
next_state <=3D s3;=20
output <=3D '0';=20
change <=3D "000000";=20
elsif N =3D '1' and D =3D '0' then=20
next_state <=3D s4;=20
output <=3D '0';=20
change <=3D "000000";=20
end if;=20
=20
when s3 =3D>=20
if N =3D '0' and D =3D '0' then=20
next_state <=3D s0;=20
output <=3D '0';=20
change <=3D "001111";=20
elsif N =3D '0' and D =3D '1' then=20
next_state <=3D s4;=20
output <=3D '0';=20
change <=3D "000000";=20
elsif N =3D '1' and D =3D '0' then=20
next_state <=3D s5;=20
output <=3D '0';=20
change <=3D "000000";=20
end if;=20
=20
when s4 =3D>=20
if N =3D '0' and D =3D '0' then=20
next_state <=3D s0;=20
output <=3D '0';=20
change <=3D "010100";=20
elsif N =3D '0' and D =3D '1' then=20
next_state <=3D s5;=20
output <=3D '0';=20
change <=3D "000000";=20
elsif N =3D '1' and D =3D '0' then=20
next_state <=3D s6;=20
output <=3D '0';=20
change <=3D "000000";=20
end if;=20
=20
when s5 =3D>=20
if N =3D '0' and D =3D '0' then=20
next_state <=3D s0;=20
output <=3D '0';=20
change <=3D "011001";=20
elsif N =3D '0' and D =3D '1' then=20
next_state <=3D s6;=20
output <=3D '0';=20
change <=3D "000000";=20
elsif N =3D '1' and D =3D '0' then=20
next_state <=3D s7;=20
output <=3D '0';=20
change <=3D "000000";=20
end if;=20
=20
when s6 =3D>=20
if N =3D '0' and D =3D '0' then=20
next_state <=3D s0;=20
output <=3D '0';=20
change <=3D "011110";=20
elsif N =3D '0' and D =3D '1' then=20
next_state <=3D s7;=20
output <=3D '0';=20
change <=3D "000000";=20
elsif N =3D '1' and D =3D '0' then=20
if RESET =3D '1' then=20
next_state <=3D s0;=20
output <=3D '1';=20
change <=3D "000000";=20
else=20
next_state <=3D s8;=20
output <=3D '1';=20
change <=3D "000000";=20
end if;=20
end if;=20
=20
when s7 =3D>=20
if N =3D '0' and D =3D '0' then=20
next_state <=3D s0;=20
output <=3D '0';=20
change <=3D "100011";=20
elsif N =3D '0' and D =3D '1' then=20
if RESET =3D '1' then=20
next_state <=3D s0;=20
output <=3D '1';=20
change <=3D "000101";=20
else=20
next_state <=3D s9;=20
output <=3D '1';=20
change <=3D "000101";=20
end if;=20
elsif N =3D '1' and D =3D '0' then=20
if RESET =3D '1' then=20
next_state <=3D s0;=20
output <=3D '1';=20
change <=3D "000000";=20
else=20
next_state <=3D s9;=20
output <=3D '1';=20
change <=3D "000000";=20
end if;=20
end if;=20
when s8 =3D>=20
if N =3D '0' and D =3D '0' then=20
if RESET =3D '1' then=20
next_state <=3D s0;=20
output <=3D '1';=20
change <=3D "000000";=20
else=20
next_state <=3D s8;=20
output <=3D '1';=20
change <=3D "000000";=20
end if;=20
end if;=20
=20
when s9 =3D>=20
if RESET =3D '1' then=20
next_state <=3D s0;=20
output <=3D '1';=20
change <=3D "000101";=20
else=20
next_state <=3D s9;=20
output <=3D '0';=20
change <=3D "000000";=20
end if;=20
=20
when others =3D>=20
next_state <=3D s0;=20
output <=3D '0';=20
change <=3D "000000";=20
end case;=20
end process;=20
=20
end architecture process_3;
Sysop: | Tetrazocine |
---|---|
Location: | Melbourne, VIC, Australia |
Users: | 4 |
Nodes: | 8 (0 / 8) |
Uptime: | 58:00:42 |
Calls: | 65 |
Files: | 21,500 |
Messages: | 73,539 |