名称:交通灯设计Verilog代码Quartus DE2-115开发板
软件:Quartus
语言:Verilog
代码功能:
交通灯设计(2人)
基本要求:
1)设计一个交通红绿灯。要求分主干道和支干道,每条道上安装红(主:R,支:r)绿(主:G,支:g)黄(主:Y,支:y)三种颜色灯,由四种状态自动循环构成;
2)在交通灯处在不同的状态时,设计一个计时器以倒计时方式显示计时,主干道上绿灯亮30S,支干道上绿灯亮20S。每个干道上,在绿灯转为红灯时,要求黄灯先亮5S。
在完成基本要求的基础上,可进一步增加功能、提高性能,如绿灯亮的时间可调。
FPGA代码Verilog/VHDL代码资源下载:www.hdlcode.com
本代码已在DE2-115开发板验证,DE2-115开发板如下,其他开发板可以修改管脚适配:
演示视频:
设计文档:
1. 工程文件
2. 程序文件
3. 程序编译
4. RTL图
5. 管脚分配
6. Testbench
7. 仿真图
部分代码展示:
/* 红->绿 绿->黄 黄->红 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,//50Mhz output main_red,//主路灯 output main_green,//主路灯 output main_yellow,//主路灯 output branch_red,//支路灯 output branch_green,//支路灯 output branch_yellow,//支路灯 output [7:0] HEX0,//(主干道)数码管0 output [7:0] HEX1,//(主干道)数码管1 output [7:0] HEX2,//(支干道)数码管2 output [7:0] HEX3//(支干道)数码管3 ); 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 ;//支路灯
点击链接获取代码文件:http://www.hdlcode.com/index.php?m=home&c=View&a=index&aid=1213
488