一个可自动可手动的交通灯
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
entity control is
port(clk:in std_logic;
hold:in std_logic_vector(2 downto 0);
ared,agreen,ayellow,bred,bgreen,byellow:out std_logic);
end control;
architecture behavior of control is
type state_type is(s0,s1,s2,s3);
signal current_state,next_state:state_type;
signal counter:std_logic_vector(2 downto 0);
begin
synch:process
begin
wait until clk'event and clk='1';
if hold="000"
then counter<="000";
elsif hold="001"
then counter<="010";
elsif hold="010"
then counter<="100";
elsif hold="011"
then counter<="101";
else
if counter<5 then
counter<=counter+1;
else
counter<=(others=>'0');
end if;
end if;
end process;
process
begin
wait until clk'event and clk='1';
current_state<=next_state;
end process;
state_trans:process(current_state)
begin
case current_state is
when s0=>
if hold="000"
then counter<="000";
elsif hold="001"
then counter<="010";
elsif hold="010"
then counter<="100";
elsif hold="011"
then counter<="101";
else
if counter<1 then
next_state<=s0;
else
next_state<=s1;
end if;
end if;
when s1=>
if hold="000"
then counter<="000";
elsif hold="001"
then counter<="010";
elsif hold="010"
then counter<="100";
elsif hold="011"
then counter<="101";
else
if counter<2
then next_state<=s1;
else
next_state<=s2;
end if;
end if;
when s2=>
if hold="000"
then counter<="000";
elsif hold="001"
then counter<="010";
elsif hold="010"
then counter<="100";
elsif hold="011"
then counter<="101";
else
if counter<4 then
next_state<=s2;
else
next_state<=s3;
end if;
end if;
when s3=>
if hold="000"
then counter<="000";
elsif hold="001"
then counter<="010";
elsif hold="010"
then counter<="100";
elsif hold="011"
then counter<="101";
else
if counter<5 then
next_state<=s3;
else
next_state<=s0;
end if;
end if;
end case;
end process;
output:process(current_state)
begin
case current_state is
when s0=>
ared<='0';
agreen<='1';
ayellow<='0';
bred<='1';
bgreen<='0';
byellow<='0';
when s1=>
ared<='0';
agreen<='0';
ayellow<='1';
bred<='1';
bgreen<='0';
byellow<='0';
when s2=>
ared<='1';
agreen<='0';
ayellow<='0';
bred<='0';
bgreen<='1';
byellow<='0';
when s3=>
ared<='1';
agreen<='0';
ayellow<='0';
bred<='0';
bgreen<='0';
byellow<='1';
end case;
end process;
end behavior;
错误显示Error (10029): Constant driver at control.vhd(41)
Error (10028): Can't resolve multiple constant drivers for net "counter[1]" at control.vhd(16)
Error (10028): Can't resolve multiple constant drivers for net "counter[0]" at control.vhd(16)
Error: Can't elaborate top-level user hierarchy
Error: Quartus II 64-Bit Analysis & Synthesis was unsuccessful. 5 errors, 22 warnings
Error: Peak virtual memory: 315 megabytes
Error: Processing ended: Wed Nov 11 18:27:03 2015
Error: Elapsed time: 00:00:01
Error: Total CPU time (on all processors): 00:00:01
Error: Quartus II Full Compilation was unsuccessful. 7 errors, 22 warnings |