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]亮???应该怎么实现
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
module LED(clk,reset_n,led);
input clk;
input reset_n;
output[3:0] led;
reg[23:0] cnt;
wire enable;
reg[3:0] led_r;
wire[3:0] led;
always @(posedge clk or negedge reset_n)
begin
if(!reset_n) cnt <= 24'b0;
else if(cnt==24'hffffff) 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 <= ~enable_r;
else enable_r <= enable_r;
end
assign enable = enable_r;
always @(posedge enable or negedge reset_n)
begin
if(!reset_n) led_r <= 4'b0000;
else led_r <= {led_r[2:0],led_r[3]};
end
assign led = led_r;
endmodule
最佳答案
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;
FPGA是硬件设计 你用c语言开发?
一周热门 更多>