用Verilog设计一个交通灯,程序已经写好。就是不知道把各个模块连接起来。
modulecontrol(clk,reset,cnt30,pout);inputclk,reset;output[6:0]cnt30;output[6:0]pout;r...
module control(clk,reset,cnt30,pout);
input clk,reset;
output[6:0] cnt30;
output[6:0] pout;
reg[6:0]pout;
reg[6:0] cnt30;
parameter s0=0,s1=1,s2=2,s3=3;
reg[3:0] cs,ns;
always @(posedge clk or negedge reset)
begin
if(reset==0) cs<=s0;
else cs<=ns; end
always@(cs,cnt30)
begin
case(cs)
s0: begin pout<=12'b011011011011;
if(cnt30==5) ns<=s1;
else ns<=s0; end
s1: begin pout<=12'b101011101011;
if(cnt30==0) ns<=s2;
else ns<=s1; end
s2: begin pout<=12'b110110110110;
if(cnt30==5) ns<=s3;
else ns<=s2; end
s3: begin pout<=12'b110101110101;
if(cnt30==0) ns<=s0;
else ns<=s3; end
default: begin pout<=12'b001001001001;
ns<=s0; end
endcase
end
always@(posedge clk or negedge reset)
begin if(reset==0) cnt30<=7'b0101001;
else
case(cs)
s0: begin if(cnt30[3:0]>0) cnt30[3:0]<=cnt30[3:0]-1;
else begin cnt30[6:4]<=cnt30[6:4]-1;
cnt30[3:0]<=4'b1001; end end
s1: begin if(cnt30==0) cnt30<=7'b0101001;
else cnt30<=cnt30-1; end
s2: begin if(cnt30[3:0]>0) cnt30[3:0]<=cnt30[3:0]-1;
else begin cnt30[6:4]<=cnt30[6:4]-1;
cnt30[3:0]<=4'b1001; end end
s3: begin if(cnt30==0) cnt30<=7'b0101001;
else cnt30<=cnt30-1; end
default: cnt30<=7'b0101001;
endcase
end
endmodule 展开
input clk,reset;
output[6:0] cnt30;
output[6:0] pout;
reg[6:0]pout;
reg[6:0] cnt30;
parameter s0=0,s1=1,s2=2,s3=3;
reg[3:0] cs,ns;
always @(posedge clk or negedge reset)
begin
if(reset==0) cs<=s0;
else cs<=ns; end
always@(cs,cnt30)
begin
case(cs)
s0: begin pout<=12'b011011011011;
if(cnt30==5) ns<=s1;
else ns<=s0; end
s1: begin pout<=12'b101011101011;
if(cnt30==0) ns<=s2;
else ns<=s1; end
s2: begin pout<=12'b110110110110;
if(cnt30==5) ns<=s3;
else ns<=s2; end
s3: begin pout<=12'b110101110101;
if(cnt30==0) ns<=s0;
else ns<=s3; end
default: begin pout<=12'b001001001001;
ns<=s0; end
endcase
end
always@(posedge clk or negedge reset)
begin if(reset==0) cnt30<=7'b0101001;
else
case(cs)
s0: begin if(cnt30[3:0]>0) cnt30[3:0]<=cnt30[3:0]-1;
else begin cnt30[6:4]<=cnt30[6:4]-1;
cnt30[3:0]<=4'b1001; end end
s1: begin if(cnt30==0) cnt30<=7'b0101001;
else cnt30<=cnt30-1; end
s2: begin if(cnt30[3:0]>0) cnt30[3:0]<=cnt30[3:0]-1;
else begin cnt30[6:4]<=cnt30[6:4]-1;
cnt30[3:0]<=4'b1001; end end
s3: begin if(cnt30==0) cnt30<=7'b0101001;
else cnt30<=cnt30-1; end
default: cnt30<=7'b0101001;
endcase
end
endmodule 展开
- 你的回答被采纳后将获得:
- 系统奖励15(财富值+成长值)+难题奖励20(财富值+成长值)
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询