3、,5s;当状态为S2时,南北方向亮红灯,东西方向绿灯,30s;当状态为S3时,南北方向亮红灯,东西方向黄灯,5s;程序还设计了一个紧急信号情况,当遭遇紧急情况时,主干道和支干道都亮红灯。7程序说明8VHDL设计代码LIBRARY IEEE; USE IEEE.STD_LOGIC_1164.ALL; USE IEEE.STD_LOGIC_UNSIGNED.ALL; USE IEEE.STD_LOGIC_ARITH; ENTITY TRAFFIC2 IS PORT (CLK,R,SPC: IN STD_LOGIC; --时钟、复位、特殊情况LIG
4、HT: OUT STD_LOGIC_VECTOR(5 DOWNTO 0); --light:G1,R1,Y1,G2,R2,Y2; Q1,Q2 : OUT INTEGER RANGE 0 TO 55); END TRAFFIC2 ; ARCHITECTURE behav OF TRAFFIC2 IS TYPE STATES IS (S0,S1,S2,S3); --定义枚举SIGNAL STATE : STATES ; SIGNAL T1,T2: INTEGER RANGE 0 TO 55;
5、 BEGIN9P1: PROCESS (CLK,STATE) BEGIN IF R='1'THEN STATE<=S0;T1<=50;T2<=55; --复位ELSIF SPC='1' THEN LIGHT<="010010"; --特殊情况亮红灯ELSIF CLK'EVENT AND CLK='1' THEN CASE STATE IS --states为s0时,南北方向亮绿灯,东西方向亮红灯,50s WHEN
6、 S0=> LIGHT<="100010"; T1<=T1-1;T2<=T2-1; Q1<=T1;Q2<=T2; IF T1=0 THEN10STATE<=S1;T1<=5;T2<=5; END IF; --states为s1时,南北方向亮黄灯,东西方向亮红,5s
7、 WHEN S1=> LIGHT<="001010"; T1<=T1-1;T2<=T2-1; Q1<=T1;Q2<=T2; IF T1=0 THEN STATE<=S2;T1<=35;T2<=30;