资源描述:
《EDA作业交通灯LXX》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、交通灯控制器一、实验目的设计交通灯控制系统设计要求如下1.东西、南北方向由红、黄、绿指示是否允许通行,绿灯定时为50秒、黄灯10秒和红灯60秒二、实验内容编写源程序代码libraryieee;useieee.std_logic_1164.all;entitytrafficisport(clk,rst:instd_logic;time1,time2:outintegerrange0to59;r1,r2,y1,y2,g1,g2:outstd_logic);endtraffic;architecturertloftrafficistypestateis(r1g2,r1y2,r2g1,r2y1
2、);signaln_state,c_state:state;signalcnt,init:integerrange0to49;signalov,load,a1,a2:std_logic;beginstate_reg:process(clk,rst)beginifrst='1'thenc_state<=r1g2;elsifclk'eventandclk='1'thenc_state<=n_state;endif;endprocess;state_com:process(c_state,ov)--状态机beginr1<='0';r2<='0';g1<='0';g2<='0';a1<='0'
3、;a2<='0';y1<='0';y2<='0';casec_stateiswhenr1g2=>a1<='1';r1<='1';g2<='1';init<=9;ifov='1'thenn_state<=r1y2;elsen_state<=r1g2;endif;whenr1y2=>r1<='1';y2<='1';init<=49;ifov='1'thenn_state<=r2g1;elsen_state<=r1y2;endif;whenr2g1=>a2<='1';r2<='1';g1<='1';init<=9;ifov='1'thenn_state<=r2y1;elsen_state<=
4、r2g1;endif;whenr2y1=>r2<='1';y1<='1';init<=49;ifov='1'thenn_state<=r1g2;elsen_state<=r2y1;endif;endcase;endprocess;process(clk,rst)beginifrst='1'thencnt<=49;elsifclk'eventandclk='1'thenifload='1'thencnt<=init;elsecnt<=cnt-1;endif;endif;endprocess;ov<='1'whencnt=0else'0';load<=ov;time1<=cnt+10whe
5、na1='1'elsecnt;time2<=cnt+10whena2='1'elsecnt;endrtl;三、实验记录及分析代码分析:对状态机的描述:r1g2r2g1r2y1r1y2ovovovova1=1;r1=1g2=1;init=9r1=1y2=1;init=49a2=1;r2=1g1=1;init=9r2=1y1=1;init=49当rst='1'时计数器赋初值49,交通灯初始状态为r1g2。当rst='0'时,1、2两路时钟同时开始计时,控制信号a1=1,time1=cnt+10,故1路红灯从59倒计时,2路绿灯从49开始倒计时。当2路计到零,进入下一个状态r1y2,init
6、=9装入计时器,第2路从9开始倒计时,第1路继续原来的计时。1、2路倒计时完成后进入下一状态r2g1,init=49装入计时器,控制信号a2=1,time2=cnt+10,故第2路从59倒计时,第1路从49开始倒计时;当第1路计到零,变r2y1,init=9装入计时器,第1路从9开始倒计时,第2路继续原来的计时;当两路同时计数到零后,变为r1g2然后转换依次转换为r1y2、r2g1、r2y1不断循环。仿真波形实验现象与设计要求一致,证明设计无误。2、可编程器件与拨码开关和发光二极管的连接情况VHDL中端口名称EPF10K10引脚号拨码开关(时钟)序号发光二极管序号rst2d0clk1c
7、lk1r18led0r229led1g17led2g26led3y128led4y260led5time1521led6time1423led7time1322led8time1227led9time1165led10time1030led11time2566time2464time2324time2210time2125time2067时钟信号拨码开关状态发光二极管状态clk1d0led0led1led2led3led4led5led6led