FPGA交通灯(控制4个数码管,成功显示倒计时)

该代码实现了一个交通十字路口红绿灯的定时控制系统,包括东西和南北方向的灯色循环以及倒计时数码显示。系统使用状态机进行灯色状态的切换,并通过BCD转码模块将计数器的值转化为数码管显示。此外,代码还考虑了不同时间段的灯光颜色变化,模拟了实际交通信号的逻辑控制。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

##一、任务要求

1)实现一交通十字路口处红绿灯的基本定时控制功能,要求东西方向灯色循环为绿灯45秒,黄灯5秒,左拐灯15秒,黄灯5秒,红灯40秒,黄灯5秒;南北方向灯色循环为红灯65秒,黄灯5秒,绿灯20秒,黄灯5秒,左拐灯15秒,黄灯5秒。

2)实现东西方向和南北方向各种灯的倒计时数码显示功能。

##二、BCD转码&&片选信号

module select(Clk_12M,Rst,led,sel,Indight_1,Indight_2,Indight_3,Indight_4,Indight_5,Indight_6);
	input Clk_12M;
	input Rst;
	output reg[6:0]led;
	output reg[5:0]sel;
	input [3:0]Indight_1;
	input [3:0]Indight_2;
	input [3:0]Indight_3;
	input [3:0]Indight_4;
	input [3:0]Indight_5;
	input [3:0]Indight_6;
	reg [7:0]segout_1;
	reg [7:0]segout_2;
	reg [7:0]segout_3;
	reg [7:0]segout_4;
	reg [7:0]segout_5;
	reg [7:0]segout_6;
	reg [15:0]count;
	 parameter start=0;
   parameter AN_1=1;
   parameter AN_2=2;
  parameter AN_3=3;
  parameter AN_4=4;
    parameter AN_5=5;
    parameter AN_6=6;
    parameter ending=7;
	reg flag;
	
	always@(posedge Clk_12M or negedge Rst)
	begin 
	if(!Rst)
	  begin
		count<=16'd0;
		flag<=1'b0;
		end
	else if (count==16'd12000)
		begin 
		  count <= 16'd0;
		  flag<=1'b1;
		end
		else
		  begin
		    count<=count+16'd1;
		    flag<=1'b0;
		    end
		 end
		
	
		
		
	
		 
		 always@(posedge Clk_12M or negedge Rst)
		 begin
		   if(!Rst)
		     segout_1<=7'b1111111;
		     else
		       begin
		 case(Indight_1)
				4'b0000: segout_1 <= 7'b0111111;
        4'b0001: segout_1 <= 7'b0000110;
        4'b0010: segout_1 <= 7'b1011011;
        4'b0011: segout_1 <= 7'b1001111;
        4'b0100: segout_1 <= 7'b1100110;
        4'b0101: segout_1 <= 7'b1101101;
        4'b0110: segout_1 <= 7'b1111101;
        4'b0111: segout_1 <= 7'b0000111;
        4'b1000: segout_1 <= 7'b1111111;
        4'b1001: segout_1 <= 7'b1101111;
				default segout_1  <= 7'b0100011;
				endcase
				end
				end
				
				always@(posedge Clk_12M or negedge Rst)
		 begin
		   if(!Rst)
		     segout_2<=7'b1111111;
		     else
		       begin
		 case(Indight_2)
					4'b0000: segout_2 <= 7'b0111111;
        4'b0001: segout_2 <= 7'b0000110;
        4'b0010: segout_2 <= 7'b1011011;
        4'b0011: segout_2 <= 7'b1001111;
        4'b0100: segout_2 <= 7'b1100110;
        4'b0101: segout_2 <= 7'b1101101;
        4'b0110: segout_2 <= 7'b1111101;
        4'b0111: segout_2 <= 7'b0000111;
        4'b1000: segout_2 <= 7'b1111111;
        4'b1001: segout_2 <= 7'b1101111;
				default segout_2  <= 7'b0100011;
				endcase
				end
				end
				
				
				always@(posedge Clk_12M or negedge Rst)
		 begin
		   if(!Rst)
		     segout_3<=7'b1111111;
		     else
		       begin
		 case(Indight_3)
					4'b0000: segout_3 <= 7'b0111111;
        4'b0001: segout_3 <= 7'b0000110;
        4'b0010: segout_3 <= 7'b1011011;
        4'b0011: segout_3 <= 7'b1001111;
        4'b0100: segout_3 <= 7'b1100110;
        4'b0101: segout_3 <= 7'b1101101;
        4'b0110: segout_3 <= 7'b1111101;
        4'b0111: segout_3 <= 7'b0000111;
        4'b1000: segout_3 <= 7'b1111111;
        4'b1001: segout_3 <= 7'b1101111;
				default segout_3  <= 7'b0100011;
				endcase
				end
				end
				
				
				
				always@(posedge Clk_12M or negedge Rst)
		 begin
		   if(!Rst)
		     segout_4<=7'b1111111;
		     else
		       begin
		 case(Indight_4)
				4'b0000: segout_4 <= 7'b0111111;
        4'b0001: segout_4 <= 7'b0000110;
        4'b0010: segout_4 <= 7'b1011011;
        4'b0011: segout_4 <= 7'b1001111;
        4'b0100: segout_4 <= 7'b1100110;
        4'b0101: segout_4 <= 7'b1101101;
        4'b0110: segout_4 <= 7'b1111101;
        4'b0111: segout_4 <= 7'b0000111;
        4'b1000: segout_4 <= 7'b1111111;
        4'b1001: segout_4 <= 7'b1101111;
				default segout_4  <= 7'b0100011;
				endcase
				end
				end
				
				
				always@(posedge Clk_12M or negedge Rst)
		 begin
		   if(!Rst)
		     segout_5<=7'b1111111;
		     else
		       begin
		 case(Indight_5)
				4'b0000: segout_5 <= 7'b0111111;
        4'b0001: segout_5 <= 7'b0000110;
        4'b0010: segout_5 <= 7'b1011011;
        4'b0011: segout_5 <= 7'b1001111;
        4'b0100
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值