📄 traffic.vhd
字号:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity traffic is
Port (Clock,Reset:in std_logic;
Strait_A_Out,Block_A_Out,Turn_A_Out,Strait_B_Out,Block_B_Out,Turn_B_Out:out std_logic;
Count_Down_LCD:out std_logic_vector(6 downto 0);
Road_sign: out std_logic_vector(13 downto 0);
Ctr:out std_logic
);
end entity;
architecture traffic of traffic is
signal Clock_4Hz,LCD:std_logic;
signal Count_4Hz:std_logic_vector(4 downto 0);
signal Count_1Hz:std_logic_vector(1 downto 0);
signal Clock_1Hz:std_logic;
signal Count_Down:std_logic_vector(2 downto 0);
--signal Count_Down_LCD:std_logic_vector(6 downto 0);
signal q:std_logic_vector(13 downto 0);
signal State:std_logic_vector(1 downto 0);
signal Count:std_logic_vector(2 downto 0);
signal Strait_A,Block_A,Turn_A,Strait_B,Block_B,Turn_B,Blink:std_logic;
--//wire [13:0] Road_sign
constant Strait_Block :std_logic_vector:="00";
constant Block_Turn :std_logic_vector:="01";
constant Turn_Block :std_logic_vector:="10";
constant Block_Strait :std_logic_vector:="11";
begin
Ctr<='1';
Strait_A_Out<=Strait_A and (Clock_4Hz or Blink);
Strait_B_Out<=Strait_B and (Clock_4Hz or Blink);
Block_A_Out<=Block_A and (Clock_4Hz or Blink);
Block_B_Out<=Block_B and (Clock_4Hz or Blink);
Turn_A_Out<=Turn_A and (Clock_4Hz or Blink);
Turn_B_Out<=Turn_B and (Clock_4Hz or Blink);
Road_sign(13 downto 7) <= q(13 downto 7);
Road_sign(6 downto 0) <= ((not q(6))and (Clock_4Hz or Blink))&((not q(5))and (Clock_4Hz or Blink))&((not q(4))and (Clock_4Hz or Blink))&
((not q(3))and (Clock_4Hz or Blink))&((not q(2))and (Clock_4Hz or Blink))&((not q(1))and (Clock_4Hz or Blink))&
((not q(0))and (Clock_4Hz or Blink));
--//************* Generate 4Hz Clock Signal from 1kHz Clock Signal **********
process(Clock)
begin
if Clock'event and Clock='1' then
Count_4Hz <= Count_4Hz-1;
if Count_4Hz="0000" then
Clock_4Hz <= not Clock_4Hz;--Generate 4Hz clock signal
end if;
end if;
end process;
--//************* Generate 1Hz Clock Signal from 4Hz Clock Signal ***********
process (Clock_4Hz)
begin
if Clock_4Hz'event and Clock_4Hz='1' then
Count_1Hz <= Count_1Hz-1;
if Count_1Hz="00" then
Clock_1Hz <= not Clock_1Hz; --//Generate 1Hz clock signal
end if;
end if;
end process;
--//**************************** Main Program *******************************
process (Clock_1Hz)
begin
if Clock_1Hz'event and Clock_1Hz='1' then
if Reset='1' then
State<=Strait_Block;
Count_Down<="000";
Strait_A<='1'; Block_A<='1'; Turn_A<='1';
Strait_B<='1'; Block_B<='1'; Turn_B<='1';
Count_Down_LCD<="1111111";
Blink<='1';
else
Count_Down<=Count_Down-1;
if State=Strait_Block then
Strait_A<='1'; Block_A<='0'; Turn_A<='0';
Strait_B<='0'; Block_B<='1'; Turn_B<='0';
if Count_Down="000" then
State<=Block_Turn;
end if;
elsif State=Block_Turn then
Strait_A<='0'; Block_A<='1'; Turn_A<='0';
Strait_B<='0'; Block_B<='0'; Turn_B<='1';
if Count_Down="000" then
State<=Turn_Block;
end if;
elsif State=Turn_Block then
Strait_A<='0'; Block_A<='0'; Turn_A<='1';
Strait_B<='0'; Block_B<='1'; Turn_B<='0';
if Count_Down="000" then
State<=Block_Strait;
end if;
elsif State=Block_Strait then
Strait_A<='0'; Block_A<='1'; Turn_A<='0';
Strait_B<='1'; Block_B<='0'; Turn_B<='0';
if Count_Down="000" then
State<=Strait_Block;
end if;
end if;
case Count_Down is
when "000"=>Count_Down_LCD<="0000110";-- //1
when "001"=>Count_Down_LCD<="1011011";-- //2
when "010"=>Count_Down_LCD<="1001111"; --//3
when "011"=>Count_Down_LCD<="1100110";-- //4
when "100"=>Count_Down_LCD<="1101101";-- //5
when "101"=>Count_Down_LCD<="1111101";-- //6
when "110"=>Count_Down_LCD<="0000111"; --//7
when "111"=>Count_Down_LCD<="1111111"; --//8
end case ;
if Count_Down>=3 then
Blink<='1';
else
Blink<='0';
end if;
end if;
end if;
end process;
process (Clock)
variable a:std_logic_vector(2 downto 0);
begin
if Clock'event and Clock='1' then
if Reset='1' then
q<="00000000000000";
else
if Count="111" then
Count<="000";
else
Count<=Count+1;
end if;
a:=Strait_A&Block_A&Turn_A;
case a is
when "100"=>case Count is
when "000"=>q<="10000001111111";
when "001"=>q<="01000001111111";
when "010"=>q<="00100001011111";
when "011"=>q<="00010000000000";
when "100"=>q<="00001001011111";
when "101"=>q<="00000101111111";
when "110"=>q<="00000011111111";
when others=> null;
end case;
when "010"=>case Count is
when "000"=>q<="10000000111110";
when "001"=>q<="01000001011101";
when "010"=>q<="00100001101011";
when "011"=>q<="00010001110111";
when "100"=>q<="00001001101011";
when "101"=>q<="00000101011101";
when "110"=>q<="00000010111110";
when others=> null;
end case;
when "001"=>case Count is
when "000"=>q<="10000001111111";
when "001"=>q<="01000001111111";
when "010"=>q<="00100001110000";
when "011"=>q<="00010001101111";
when "100"=>q<="00001001101111";
when "101"=>q<="00000101000111";
when "110"=>q<="00000011101111";
when others=> null;
end case;
when others=> null;
end case;
end if;
end if;
end process;
end traffic;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -