📄 t_led.v
字号:
module T_LED(clk,out_LED7_NS,out_LED7_WE,out_LED3_NS,out_LED3_WE,clk_1S,Time_10,Time_1,Time_Y,in_NS,in_WE);
input clk;
input[2:0] in_NS,in_WE;
wire clk_1S;
output[3:0] Time_10,Time_1;
output Time_Y;
output Clk_1S;
output[13:0] out_LED7_NS,out_LED7_WE;
reg[13:0] out_LED7_NS,out_LED7_WE;
output[2:0] out_LED3_NS,out_LED3_WE;
reg[2:0] out_LED3_NS,out_LED3_WE;
reg[7:0] TIME;
clkToclk_1S
Second(.clk(clk),.clk_1S(clk_1S));
reg[3:0] Time_10,Time_1;
reg[2:0] Time_Y;
reg[1:0] Stage;
always@(posedge clk_1S)begin
case(Stage)
2'b00:begin//NS pass
if((Time_10==0)&(Time_1==0))begin
Stage<=2'b11;
Time_Y<=3'd3;
end
else begin
if(Time_1==0)begin
Time_1<=4'd9;
Time_10<=Time_10-1;
end
else begin
Time_1<=Time_1-1;
end
end
out_LED7_NS<={out_LED7_NUM(Time_10),out_LED7_NUM(Time_1)};
out_LED7_WE<={out_LED7_NUM(Time_10),out_LED7_NUM(Time_1)};
out_LED3_NS<=3'b001;
out_LED3_WE<=3'b100;
end
2'b01:begin//WE pass
if((Time_10==0)&(Time_1==0))begin
Stage<=2'b10;
Time_Y<=3'd3;
end
else begin
if(Time_1==0)begin
Time_1<=4'd9;
Time_10<=Time_10-1;
end
else begin
Time_1<=Time_1-1;
end
end
out_LED7_WE<={out_LED7_NUM(Time_10),out_LED7_NUM(Time_1)};
out_LED7_NS<={out_LED7_NUM(Time_10),out_LED7_NUM(Time_1)};
out_LED3_WE<=3'b001;
out_LED3_NS<=3'b100;
end
2'b10:begin//Yellow to NS pass
if(Time_Y==0)begin
Stage<=2'b00;
Time_10={1'b0,in_NS}+4'd1;
Time_1=4'd0;
end
else begin
Time_Y<=Time_Y-1;
end
out_LED7_WE<={out_LED7_NUM(4'd0),out_LED7_NUM(Time_Y)};
out_LED7_NS<={out_LED7_NUM(4'd0),out_LED7_NUM(Time_Y)};
out_LED3_WE<=3'b010;
out_LED3_NS<=3'b010;
end
2'b11:begin//Yellow to WE pass
if(Time_Y==0)begin
Stage<=2'b01;
Time_10={1'b0,in_WE}+4'd1;
Time_1=4'd0;
end
else begin
Time_Y<=Time_Y-1;
end
out_LED7_NS<={out_LED7_NUM(4'd0),out_LED7_NUM(Time_Y)};
out_LED7_WE<={out_LED7_NUM(4'd0),out_LED7_NUM(Time_Y)};
out_LED3_NS<=3'b010;
out_LED3_WE<=3'b01;
end
default:begin
Stage<=2'b00;
Time_10=4'd2;
Time_1=4'd0;
end
endcase
end
function[6:0]out_LED7_NUM;
input[3:0] in_NUM;
begin
case(in_NUM)
4'd00:out_LED7_NUM=7'b111_1110;
4'd01:out_LED7_NUM=7'b011_0000;
4'd02:out_LED7_NUM=7'b110_1101;
4'd03:out_LED7_NUM=7'b111_1001;
4'd04:out_LED7_NUM=7'b011_0011;
4'd05:out_LED7_NUM=7'b101_1011;
4'd06:out_LED7_NUM=7'b101_1111;
4'd07:out_LED7_NUM=7'b111_0000;
4'd08:out_LED7_NUM=7'b111_1111;
4'd09:out_LED7_NUM=7'b111_0011;
default:out_LED7_NUM=7'b111_1111;
endcase
end
endfucntion
endmodule
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -