资源描述:
《基于VHDL语言的交通灯》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、LIBRARYIEEE;USEIEEE.STD_LOGIC_1164.ALL;USEIEEE.STD_LOGIC_UNSIGNED.ALL;USEIEEE.STD_LOGIC_ARITH.ALL;ENTITYtrafficISPORT(CLK,R,SP,fault:INSTD_LOGIC;eLIGHT:BUFFERSTD_LOGIC_VECTOR(2DOWNTO0);--东:绿,黄,红sLIGHT:BUFFERSTD_LOGIC_VECTOR(2DOWNTO0);--南:绿,黄,红wLIGHT:BUFFERSTD_LOGIC_VECTOR(2DOWNTO0)
2、;--西:绿,黄,红nLIGHT:BUFFERSTD_LOGIC_VECTOR(2DOWNTO0);--北:绿,黄,红SEL:BUFFERSTD_LOGIC_VECTOR(2DOWNTO0);Q1,Q2:OUTINTEGERRANGE0TO24;---------倒计时SMG:OUTSTD_LOGIC_VECTOR(7DOWNTO0));ENDtraffic;ARCHITECTURERT1OFtrafficISTYPESTATESIS(S0,S1,S2,S3);SIGNALSTATE:STATES;SIGNALCLK1HZ:STD_LOGIC;SIGNALT
3、:INTEGERRANGE0TO10;SIGNALT1,T2:INTEGERRANGE0TO24;SIGNALL1,L2,L3,L4:INTEGERRANGE0TO10;BEGINP1:PROCESS(CLK)------产生1Hz时钟的分频计数器VARIABLEcnt:INTEGERRANGE0TO512;BEGINIFCLK='1'ANDCLK'EVENTTHENIFcnt=511THENcnt:=0;ELSEIFcnt<256THENCLK1HZ<='1';ELSECLK1HZ<='0';ENDIF;cnt:=cnt+1;ENDIF;ENDIF;END
4、PROCESS;----------------------------------------------------P2:PROCESS(CLK1HZ,fault,T1,T2,SP,R,eLIGHT(1),sLIGHT(1),wLIGHT(1),nLIGHT(1))BEGINIFR='1'THENSTATE<=S0;T1<=16;T2<=19;--初始状态ELSIFSP='1'THEN-------------------紧急状态eLIGHT<="001";sLIGHT<="001";wLIGHT<="001";nLIGHT<="001";STATE<=
5、S0;T1<=16;T2<=19;ELSIFfault='1'THEN-----------------系统出现故障eLIGHT<="010";sLIGHT<="010";wLIGHT<="010";nLIGHT<="010";eLIGHT(1)<=CLK1HZ;sLIGHT(1)<=CLK1HZ;wLIGHT(1)<=CLK1HZ;nLIGHT(1)<=CLK1HZ;STATE<=S0;T1<=16;T2<=19;ELSIF(CLK1HZ'EVENTANDCLK1HZ='1')THEN------正常运行CASESTATEIS---------------
6、-----------------------------------------------WHENS0=>eLIGHT<="001";wLIGHT<="001";--禁东西干道sLIGHT<="100";nLIGHT<="100";--通南北干道T1<=T1-1;T2<=T2-1;Q1<=T1;Q2<=T2;IFT1=0THENSTATE<=S1;T1<=2;T2<=2;ENDIF;WHENS1=>eLIGHT<="001";wLIGHT<="001";sLIGHT<="010";nLIGHT<="010";--南北黄灯T1<=T1-1;T2<=T2-1
7、;Q1<=T1;Q2<=T2;IFT1=0THENSTATE<=S2;T1<=24;T2<=19;ENDIF;---------------------------------------------------------------WHENS2=>eLIGHT<="100";wLIGHT<="100";--通东西干道sLIGHT<="001";nLIGHT<="001";--禁南北干道T1<=T1-1;T2<=T2-1;Q1<=T1;Q2<=T2;IFT2=0THENSTATE<=S3;T1<=4;T2<=4;ENDIF;WHENS3=>eLIGHT<=
8、"010";wLIGHT<="010";--东西黄灯