名称:十字路口交通灯设计Verilog代码VIVADO仿真(文末获取)
软件:VIVADO
语言:Verilog
代码功能:
十字路口交通灯
基本要求:基本交通模型十字路口,4组路灯,联动控制。通过led显示交通控制,常亮为通行,闪烁为缓行,灭灯为禁行。整个设计通过状态机控制。
测试仿真:testbench包含1个完整交通控制周期过程。
提示:设计定时状态机控制;
1. 交通灯设计
功能描述:设计十字路口的交通灯,分为主路支路红绿灯,每条路2组一致,一共4组。两条路的时间相同,均为红灯33秒,绿灯30秒,黄灯闪烁3秒。
2. 工程文件
3. 程序文件
4. 程序编译
5. RTL图
6. 仿真文件(testbench)
7. 仿真图
部分代码展示:
/* 红->绿 绿->黄 黄->红 1、红--计时main_red_times------------------------绿--计时main_green_times---main_yellow_times黄灯---------------红 2、绿--计时branch_green_times---branch_yellow_times黄灯--------------------红--计时branch_reg_times-------------------绿 */ //设路口A为主路,路口B为支路 module traffic_light( input clk,//时钟 //4组路灯,led 1亮0灭 output [2:0]main_LED_1,//主路灯1 output [2:0]main_LED_2,//主路灯2 output [2:0]branch_LED_1,//支路灯1 output [2:0]branch_LED_2//支路灯2 ); wire clk_1Hz; reg main_red;//主路灯 reg main_green;//主路灯 reg main_yellow;//主路灯 reg branch_red;//支路灯 reg branch_green;//支路灯 reg branch_yellow;//支路灯 //led 1亮0灭 assign main_LED_1[0]=main_red;//主路灯 assign main_LED_1[1]=main_green;//主路灯 assign main_LED_1[2]=main_yellow ;//主路灯 assign main_LED_2[0]=main_red;//主路灯 assign main_LED_2[1]=main_green;//主路灯 assign main_LED_2[2]=main_yellow ;//主路灯 assign branch_LED_1[0]=branch_red;//支路灯 assign branch_LED_1[1]=branch_green;//支路灯 assign branch_LED_1[2]=branch_yellow ;//支路灯 assign branch_LED_2[0]=branch_red;//支路灯 assign branch_LED_2[1]=branch_green;//支路灯 assign branch_LED_2[2]=branch_yellow ;//支路灯 //分频模块 //分频到1Hz reg [31:0] cnt='d0; reg clk_1hz=0; assign clk_1Hz=clk_1hz; always@(posedge clk)//分频 if(cnt==32'd250) begin//分频500,得1HZ,250 cnt<=32'd0; clk_1hz<=~clk_1hz; end else begin cnt<=cnt+32'd1; clk_1hz<=clk_1hz; end
源代码
扫描文章末尾的公众号二维码