赞
踩
名称:DE0开发板交通灯控制器红绿灯时间可配
软件:QuartusII
语言:VHDL
代码功能:
要求:设计一个十字路口交通信号灯的控制电路。
要求红、绿灯按一定的规律亮和灭,并在亮灯期间进行倒计时,且将运行时间用数码管显示出来。
绿灯亮时,为该车道允许通行信号,红灯亮时,为该车道禁止通行信号。
该代码的主路支路通行时间可根据要求自行设置,
默认主路绿灯25s,主路黄灯5s,支路绿灯20s,支路黄灯5s
设置时间时,在顶层文件找到以下代码,修改对应时间的二进制值即可
--设置时间,可自行修改时间, G1_time <= "00011001";--主路绿灯25s Y1_time <= "00000101";--主路黄灯5s G2_time <= "00010100";--支路绿灯20s Y2_time <= "00000101";--支路黄灯5s
本代码已在DE0开发板验证,开发板如下:
FPGA代码Verilog/VHDL代码资源下载网:www.hdlcode.com
代码下载:
部分代码展示
LIBRARY ieee; USE ieee.std_logic_1164.all; ENTITY Traffic_Light_Control IS PORT ( clk : IN STD_LOGIC;--50Mhz control : IN STD_LOGIC;--紧急控制按键 R1 : OUT STD_LOGIC;--高电平亮,主路红灯 G1 : OUT STD_LOGIC;--高电平亮,主路绿灯 Y1 : OUT STD_LOGIC;--高电平亮,主路黄灯 R2 : OUT STD_LOGIC;--高电平亮,支路红灯 G2 : OUT STD_LOGIC;--高电平亮,支路绿灯 Y2 : OUT STD_LOGIC;--高电平亮,支路黄灯 HEX0 : OUT STD_LOGIC_VECTOR(6 DOWNTO 0);--数码管0 HEX1 : OUT STD_LOGIC_VECTOR(6 DOWNTO 0);--数码管1 HEX2 : OUT STD_LOGIC_VECTOR(6 DOWNTO 0);--数码管2 HEX3 : OUT STD_LOGIC_VECTOR(6 DOWNTO 0)--数码管3 ); END Traffic_Light_Control; ARCHITECTURE behave OF Traffic_Light_Control IS --分频模块 COMPONENT CLOCK IS-- Divide 50MHz to 1Hz GENERIC(D : INTEGER := 50000000);--仿真时改小为500加快仿真速度,实际上板验证时改为50000000 PORT(CLK: IN STD_LOGIC; DAV: OUT STD_LOGIC); END COMPONENT; --显示模块 COMPONENT HEX IS PORT ( clk : IN STD_LOGIC; SMG_1 : IN STD_LOGIC_VECTOR(7 DOWNTO 0); SMG_2 : IN STD_LOGIC_VECTOR(7 DOWNTO 0); HEX0 : OUT STD_LOGIC_VECTOR(6 DOWNTO 0); HEX1 : OUT STD_LOGIC_VECTOR(6 DOWNTO 0); HEX2 : OUT STD_LOGIC_VECTOR(6 DOWNTO 0); HEX3 : OUT STD_LOGIC_VECTOR(6 DOWNTO 0) ); END COMPONENT; --显示值计算模块 COMPONENT SMG IS PORT ( clk : IN STD_LOGIC; R1 : IN STD_LOGIC; G1 : IN STD_LOGIC; Y1 : IN STD_LOGIC; R2 : IN STD_LOGIC; G2 : IN STD_LOGIC; Y2 : IN STD_LOGIC; G1_BCD : IN STD_LOGIC_VECTOR(7 DOWNTO 0); Y1_BCD : IN STD_LOGIC_VECTOR(7 DOWNTO 0); R1_BCD : IN STD_LOGIC_VECTOR(7 DOWNTO 0); G2_BCD : IN STD_LOGIC_VECTOR(7 DOWNTO 0); Y2_BCD : IN STD_LOGIC_VECTOR(7 DOWNTO 0); R2_BCD : IN STD_LOGIC_VECTOR(7 DOWNTO 0); G1_time : IN STD_LOGIC_VECTOR(7 DOWNTO 0); Y1_time : IN STD_LOGIC_VECTOR(7 DOWNTO 0); G2_time : IN STD_LOGIC_VECTOR(7 DOWNTO 0); Y2_time : IN STD_LOGIC_VECTOR(7 DOWNTO 0); SMG1 : OUT STD_LOGIC_VECTOR(7 DOWNTO 0); SMG2 : OUT STD_LOGIC_VECTOR(7 DOWNTO 0) ); END COMPONENT; --交通灯控制模块 COMPONENT RGY IS PORT ( clk_1 : IN STD_LOGIC; control : IN STD_LOGIC;--紧急控制按键 G1_time : IN STD_LOGIC_VECTOR(7 DOWNTO 0); Y1_time : IN STD_LOGIC_VECTOR(7 DOWNTO 0); G2_time : IN STD_LOGIC_VECTOR(7 DOWNTO 0); Y2_time : IN STD_LOGIC_VECTOR(7 DOWNTO 0); R1 : OUT STD_LOGIC; G1 : OUT STD_LOGIC; Y1 : OUT STD_LOGIC; R2 : OUT STD_LOGIC; G2 : OUT STD_LOGIC; Y2 : OUT STD_LOGIC; G1_BCD : OUT STD_LOGIC_VECTOR(7 DOWNTO 0); Y1_BCD : OUT STD_LOGIC_VECTOR(7 DOWNTO 0); R1_BCD : OUT STD_LOGIC_VECTOR(7 DOWNTO 0); G2_BCD : OUT STD_LOGIC_VECTOR(7 DOWNTO 0); Y2_BCD : OUT STD_LOGIC_VECTOR(7 DOWNTO 0); R2_BCD : OUT STD_LOGIC_VECTOR(7 DOWNTO 0) ); END COMPONENT; SIGNAL clk_1 : STD_LOGIC; SIGNAL G1_BCD : STD_LOGIC_VECTOR(7 DOWNTO 0); SIGNAL Y1_BCD : STD_LOGIC_VECTOR(7 DOWNTO 0); SIGNAL R1_BCD : STD_LOGIC_VECTOR(7 DOWNTO 0); SIGNAL G2_BCD : STD_LOGIC_VECTOR(7 DOWNTO 0); SIGNAL Y2_BCD : STD_LOGIC_VECTOR(7 DOWNTO 0); SIGNAL R2_BCD : STD_LOGIC_VECTOR(7 DOWNTO 0); SIGNAL SMG1 : STD_LOGIC_VECTOR(7 DOWNTO 0); SIGNAL SMG2 : STD_LOGIC_VECTOR(7 DOWNTO 0); SIGNAL R1_led : STD_LOGIC; SIGNAL G1_led : STD_LOGIC; SIGNAL Y1_led : STD_LOGIC; SIGNAL R2_led : STD_LOGIC; SIGNAL G2_led : STD_LOGIC; SIGNAL Y2_led : STD_LOGIC; SIGNAL G1_time : STD_LOGIC_VECTOR(7 DOWNTO 0); SIGNAL Y1_time : STD_LOGIC_VECTOR(7 DOWNTO 0); SIGNAL G2_time : STD_LOGIC_VECTOR(7 DOWNTO 0); SIGNAL Y2_time : STD_LOGIC_VECTOR(7 DOWNTO 0); SIGNAL HEX0_SIG : STD_LOGIC_VECTOR(6 DOWNTO 0); SIGNAL HEX1_SIG : STD_LOGIC_VECTOR(6 DOWNTO 0); SIGNAL HEX2_SIG : STD_LOGIC_VECTOR(6 DOWNTO 0); SIGNAL HEX3_SIG : STD_LOGIC_VECTOR(6 DOWNTO 0); BEGIN HEX0 <= HEX0_SIG; HEX1 <= HEX1_SIG; HEX2 <= HEX2_SIG; HEX3 <= HEX3_SIG; R1 <= R1_led;--主路红灯 G1 <= G1_led;--主路绿灯 Y1 <= Y1_led;--主路黄灯 R2 <= R2_led;--支路红灯 G2 <= G2_led;--支路绿灯 Y2 <= Y2_led;--支路黄灯 --分频到1hz U_CLOCK : CLOCK PORT MAP ( clk => clk, dav => clk_1 ); --设置时间,可自行修改时间, --主路红灯时间等于支路绿灯加黄灯 --支路红灯时间等于主路绿灯加黄灯 --红灯25s,绿灯20s,黄灯5s G1_time <= "00011001";--主路绿灯25s Y1_time <= "00000101";--主路黄灯5s G2_time <= "00010100";--支路绿灯20s Y2_time <= "00000101";--支路黄灯5s --交通灯控制模块 U1 : RGY PORT MAP ( clk_1 => clk_1, control => control, R1 => R1_led, G1 => G1_led, Y1 => Y1_led, R2 => R2_led, G2 => G2_led, Y2 => Y2_led, G1_time => G1_time, Y1_time => Y1_time, G2_time => G2_time, Y2_time => Y2_time, G1_BCD => G1_BCD,--绿灯时间 Y1_BCD => Y1_BCD,--黄灯时间 R1_BCD => R1_BCD,--红灯时间 G2_BCD => G2_BCD,--绿灯时间 Y2_BCD => Y2_BCD,--黄灯时间 R2_BCD => R2_BCD--红灯时间 ); --倒计时数据计算模块 U2 : SMG PORT MAP ( clk => clk, R1 => R1_led, G1 => G1_led, Y1 => Y1_led, R2 => R2_led, G2 => G2_led, Y2 => Y2_led, G1_BCD => G1_BCD, Y1_BCD => Y1_BCD, R1_BCD => R1_BCD, G2_BCD => G2_BCD, Y2_BCD => Y2_BCD, R2_BCD => R2_BCD, G1_time => G1_time, Y1_time => Y1_time, G2_time => G2_time, Y2_time => Y2_time, SMG1 => SMG1,--数码管显示 SMG2 => SMG2--数码管显示 ); --数码管显示模块 U3 : HEX PORT MAP ( clk => clk, SMG_1 => SMG1,--数码管数据显示 SMG_2 => SMG2,--数码管数据显示 HEX0 => HEX0_SIG,--低电平亮 HEX1 => HEX1_SIG,--低电平亮 HEX2 => HEX2_SIG,--低电平亮 HEX3 => HEX3_SIG--低电平亮 ); END behave;
设计文档:
1. 工程文件
2. 程序文件
3. 程序编译
4. RTL图
5. 管脚分配
6. Testbench
7. 仿真图
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。