十字路口分东南西北四个方向,其中东西方向灯亮一致,南北方向灯亮一致; 东西红灯亮,南北绿灯亮,延时30S转为黄灯; 再延时4S东西转为绿灯,南北转为红灯; 再延时30S转为黄灯; 延时4S东西转回红灯,南北转回绿灯;如此循环 分为定时和控制两部分 SM为东西方向控制键,设为高电平 SB为南北方向控制键,设为低电平 如此,系统进入稳定状态。 CLK:时钟脉冲 MR:东西红灯 MY:东西黄灯 MG:东西绿灯 BR:南北红灯 BY:南北黄灯 BG:南北绿灯 LIBRARY IEEE; USE IEEE.STD_LOGIC_1164.ALL; ENTITY jiaotongdeng IS PORT(CLK,SM ,SB : IN BIT; MR,MY,MG,BR,BY,BG:OUT BIT); END jiaotongdeng; ARCHITECTURE ART 0F jiaotongdeng IS TYPE STATE_TYPE IS(A,B,C,D); SIGNAL STATE:STATE_TYPE ; BEGIN CNTROCESS(CLK) VARIABLE S :INTEGER RANGE 0 T0 29 ; VARIABLE CLR,EN:BIT; BEGIN IF(ClK'EVENT AND CLK='1')THEN IF CLR= '0' THEN S:=0; ELSIF EN='0' THEN S:=S; ELSE S:=S+1; END IF; CASE STATE IS WHEN A=>MR<='0';MY<='0';MG<='1'; BR<='1';BY<='0';BG<='0'; IF(SM AND (NOT SB))='1' THEN IF (S=29) THEN STATE<=B:CLR:='0';EN:='0'; ELSE STATE<=A;CLR:='1';EN:='1'; END IF ; END IF ; WHEN B=>MR<='0';MY<='1';MG<='0'; BR<='0';BY<='1';BG<='0'; IF (S=3) THEN STATE<=C;CLR:='0';EN:='0'; ELSE STATE<=B;CLR:='1';EN:='1'; END IF; WHEN C=>MR<='1';MY<='0';MG<='0'; BR<='0';BY<='0';BG<='1'; IF (S=29) THEN STATE<=D;CLR:='0';EN:='0'; ELSE STATE<=C;CLR:='0';EN:='1'; END IF; WHEN D=>MR<='0';MY<='1';MG<='0'; BR<='0';BY<='1';BG<='0'; IF (S=3) THEN STATE<=A;CLR:='0';EN:='0'; ELSE STATE<=D;CLR:='1';EN:='1'; END IF; END CASE; END IF; END PROCESS CNT; END ART; |