module LED(clk,reset_n,led);
input clk;
input reset_n;
output[3:0] led;
reg[23:0] cnt;
always @(posedge clk or negedge reset_n)
begin
if(!reset_n)
cnt <= 24'b0;
else
cnt <= cnt + 1'b1;
end
reg enable_r;
always @(posedge clk or negedge reset_n)
begin
if(!reset_n)
enable_r <= 1'b0;
else if (cnt == 24'hffffff)
enable_r <= 1'b1;
else
enable_r <= 1'b0;
end
wire enable;
assign enable = enable_r;
reg[3:0] led_r;
always @(posedge clk or negedge reset_n)
begin
if(!reset_n)
led_r <= 4'b0000;
else
begin
led_r <= 4'b0001;
if(enable)
led_r <= {led_r[0],led_r[3:1]};
end
end
wire[3:0] led;
assign led = led_r;
endmodule
想实现复位时全灭,不复位时流水灯为什么最后
always @(posedge clk or negedge reset_n)
begin
if(!reset_n)
led_r <= 4'b0000;
else
begin
led_r <= 4'b0001;
if(enable)
led_r <= {led_r[0],led_r[3:1]};
end
end
这么写实现复位,但是不复位时只有led_r[0]亮???应该怎么实现
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
这应该没错,是后边,应该是这么写吧always @(posedge clk or negedge reset_n)begin
if(!reset_n)
begin
led_r <= 4'b0000;
first<=1'b1;
end
else if(enable)
begin
if(first)
begin
led_r <= 4'b0001;
first<=0;
end
else
led_r <= {led_r[0],led_r[3:1]};
end
end
wire[3:0] led;
assign led = led_r;
endmodule
一周热门 更多>