• 方案介绍
  • 附件下载
  • 相关推荐
申请入驻 产业图谱

十字路口交通灯Verilog代码vivado ego1开发板

06/15 08:48
963
加入交流群
扫码加入
获取工程师必备礼包
参与热点资讯讨论

2-231230105KU60.docx

共1个文件

名称:十字路口交通灯Verilog代码vivado  ego1开发板

软件:vivado

语言:Verilog

代码功能:

十字路口交通灯

1、具有主路和支路两个路口交通灯;

2、可以通过开关控制主路常绿、主路和支路交替通行;

3、数码管显示倒计时;

4、红绿灯时间可以通过修改代码参数设置。

上板操作步骤:

下载bit文件到板子,SW0开关控制红绿灯方式,为1表示主路常绿(主路通行),为0正常红绿灯(主路支路交替通行,数码管显示倒计时)。

FPGA代码Verilog/VHDL代码资源下载:www.hdlcode.com

本代码已在ego1开发板验证,ego1开发板如下,其他开发板可以修改管脚适配:

ego1开发板.png

演示视频:

设计文档:

可按以下代码修改红绿灯时间,修改后面的数字即可

1. 工程文件

2. 程序文件

3. 程序编译

4. RTL图

5. 管脚约束

6. Testbench

7. 仿真图

将红绿灯信号用对应颜色表示

8. 上板操作

按教程下载bit文件到板子,SW0开关控制红绿灯方式,为1表示主路常绿(主路通行),为0正常红绿灯(主路支路交替通行,数码管显示倒计时)。

部分代码展示:

/*
红->绿 绿->黄 黄->红
1、红--计时main_red_times------------------------绿--计时main_green_times---main_yellow_times黄灯---------------红
2、绿--计时branch_green_times---branch_yellow_times黄灯--------------------红--计时branch_reg_times-------------------绿
*/
module traffic_light(
input clk,//100MMhz
input lock_key,//控制按键--为1表示主路常绿,为0正常红绿灯(主路支路交替通行)
output main_red,//主路灯
output main_green,//主路灯
output main_yellow,//主路灯
output branch_red,//支路灯
output branch_green,//支路灯
output branch_yellow,//支路灯
output [3:0] weixuan,//数码管位选
output [7:0] duanxian//数码管段选
);
 wire clk_1Hz;
 wire [7:0] main_green_BCD;
 wire [7:0] main_yellow_BCD;
 wire [7:0] main_red_BCD;
 wire [7:0] branch_green_BCD;
 wire [7:0] branch_yellow_BCD;
 wire [7:0] branch_red_BCD;
 wire [7:0] main_data_out;
 wire [7:0] branch_data_out;
 
wire main_red_led;//主路灯
wire main_green_led;//主路灯
wire main_yellow_led;//主路灯
wire branch_red_led;//支路灯
wire branch_green_led;//支路灯
wire branch_yellow_led;//支路灯
assign main_red=main_red_led;//主路灯
assign main_green=main_green_led;//主路灯
assign main_yellow=main_yellow_led ;//主路灯
assign branch_red=branch_red_led;//支路灯
assign branch_green=branch_green_led;//支路灯
assign branch_yellow=branch_yellow_led ;//支路灯 
//分频模块
div div100
(
. clk(clk),
. clk_out(clk_1Hz)
);
//调整时间
wire [7:0]main_green_time;
wire [7:0]main_yellow_time;
wire [7:0]branch_green_time;
wire [7:0]branch_yellow_time;
//可按键要求自行设置
assign main_yellow_time=8'd3;//主路黄灯时间3秒
assign branch_yellow_time=8'd3;//支路黄灯时间3秒
assign main_green_time=8'd15;//主路绿灯时间15秒
assign branch_green_time=8'd15;//支路灯的时间15秒
///////////////////////////////
reg [7:0] display_main;
reg [7:0] display_branch;
////////////////////////////////
//交通灯控制模块
led led(
. clk_1Hz(clk_1Hz),
. lock_key(lock_key),//控制按键--为1表示主路常绿,为0正常红绿灯(主路支路交替通行)
. main_red(main_red_led),//主路灯
. main_green(main_green_led),//主路灯
. main_yellow(main_yellow_led),//主路灯
. branch_red(branch_red_led),//支路灯
. branch_green(branch_green_led),//支路灯
. branch_yellow(branch_yellow_led),//支路灯
. main_green_time(main_green_time),
. main_yellow_time(main_yellow_time),
. branch_green_time(branch_green_time),
. branch_yellow_time(branch_yellow_time),
. main_green_BCD(main_green_BCD),//绿灯时间计数
. main_yellow_BCD(main_yellow_BCD),//黄灯时间计数
. main_red_BCD(main_red_BCD),//红灯时间计数
. branch_green_BCD(branch_green_BCD),//绿灯时间计数
. branch_yellow_BCD(branch_yellow_BCD),//黄灯时间计数
. branch_red_BCD(branch_red_BCD)//红灯时间计数
);
//显示数据生成模块
shumaguan_data shumaguan_data(
. clk(clk),
. main_red(main_red_led),//主路灯
. main_green(main_green_led),//主路灯
. main_yellow(main_yellow_led),//主路灯
. branch_red(branch_red_led),//支路灯
. branch_green(branch_green_led),//支路灯
. branch_yellow(branch_yellow_led),//支路灯
. main_green_BCD(main_green_BCD),//绿灯时间计数
. main_yellow_BCD(main_yellow_BCD),//黄灯时间计数
. main_red_BCD(main_red_BCD),//红灯时间计数
. branch_green_BCD(branch_green_BCD),//绿灯时间计数
. branch_yellow_BCD(branch_yellow_BCD),//黄灯时间计数
. branch_red_BCD(branch_red_BCD),//红灯时间计数
. main_green_time(main_green_time),
. main_yellow_time(main_yellow_time),
. branch_green_time(branch_green_time),
. branch_yellow_time(branch_yellow_time),
. main_data_out(main_data_out),//主路数码管数据显示
. branch_data_out(branch_data_out)//支路数码管数据显示
);
display display
(
. clk(clk),
. lock_key(lock_key),
. main_data(main_data_out),//主路数码管数据显示
. branch_data(branch_data_out),//支路数码管数据显示
. weixuan(weixuan),//位选,高电平亮
. duanxian(duanxian)//段选,高电平亮
);
endmodule

点击链接获取代码文件:http://www.hdlcode.com/index.php?m=home&c=View&a=index&aid=456

  • 2-231230105KU60.docx
    下载

相关推荐