📄 traffic.vhd
字号:
LIBRARY IEEE;
USE IEEE.STD_LOGIC_1164.ALL;
USE IEEE.STD_LOGIC_ARITH.ALL;
ENTITY traffic IS
PORT( en: IN STD_LOGIC;
clk: IN STD_LOGIC;
rst: IN STD_LOGIC;
q: OUT STD_LOGIC_VECTOR(11 DOWNTO 0)
);
-- Set the time of the yellow light according to the clock
CONSTANT number1 : INTEGER := 2;
-- Set the time of the green light according to the clock
CONSTANT number2 : INTEGER := 5;
END traffic;
ARCHITECTURE func1 OF traffic IS
BEGIN
PROCESS(clk)
VARIABLE temp1: INTEGER RANGE 0 TO 20;
VARIABLE temp2: INTEGER RANGE 0 TO 2;
BEGIN
IF(rst = '0') THEN
q<="000000000000";
ELSIF(clk'EVENT AND clk='1')THEN
IF(en = '1') THEN
temp1 := temp1 + 1;
IF(temp1 = number1 AND temp2 = 0) THEN
q<="001100100001"; -- Direction A
temp2 := temp2 + 1;
ELSIF(temp1 = number2 AND temp2 = 1) THEN
q<="001010010001"; -- Direction A to Direction B
temp1 := 0;
temp2 := temp2 + 1;
ELSIF(temp1 = number1 AND temp2 = 2) THEN
q<="100001001100"; -- Direction B
temp2 := temp2 + 1;
ELSIF(temp1 = number2 AND temp2 = 3) THEN
q<="010001001010"; -- Direction B to Direction A
temp1 := 0;
temp2 := 0;
END IF;
END IF;
END IF;
END PROCESS;
END func1;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -