• 已绑定课时
  • 工程师可点评
  • 需修改

1、请画出1s跑马灯的时序图?

王梓栋
287 3 1
需修改工程师评优秀3
教务评价

需修改

3342599708 · 2026-11-23

2、计数器从0开始计数的话,只能计到最大值-1.好比从0开始数数,数到6,一共就是7个数了,这里也是同理。 always @(posedge sysclk) begin   if(rst_n == 0) cont <= 0;   else begin     if(cont < Time_1s - 1)  //未计满1s cont <= cont +1;     else //这个else就是对上一个条件的否定,也就是cnt>=Time_1s-1的时候 cont <= 0;        //清0,重复计数   end end always @(posedge sysclk) begin   if(rst_n == 0) led <= 4'b0011;   else    begin     if(cont < Time_1s-1)      //未计满1s led <= led;     else // 这个else就是对上一个条件的否定,也就是cnt>=Time_1s-1的时候 led <= {led[1:0],led[3:2]};  //还可以替换成led<=~led;//按位取反。   end end

1、请画出1s跑马灯的时序图?

2、请使用Verilog设计一个翻转灯:led隔1s翻转一次,led一开始亮两个灯,1s之后亮另外两个灯(写出详细的代码)?

`timescale 1ns / 1ps
// 翻转灯:led隔1s翻转一次,led一开始亮两个灯,1s之后亮另外两个灯
module Flip_LED(
input sysclk,
input rst_n,
output  reg [3:0] led
);
parameter Time_1s = 26'd50000000;
reg [25:0] cont;
always @(posedge sysclk)
begin
if(rst_n == 0)
cont <= 0;
else
begin
if(cont < Time_1s)
cont <= cont +1;
else if(cont == Time_1s)
cont <= 0;
else
cont <= cont;
end
end
always @(posedge sysclk)
begin
if(rst_n == 0)
led <= 4'b0011;
else
begin
if(cont < Time_1s)
led <= led;
else if(cont == Time_1s)
led <= {led[1:0],led[3:2]};
else
led <= led;
end
end
endmodule

修改历程

1 条批注

你的每次提交都会留档,老师的每次批注也会保留。按批注修改后重新提交,不会覆盖历史版本。

  1. v1当前
  2. 需修改
    2、计数器从0开始计数的话,只能计到最大值-1.好比从0开始数数,数到6,一共就是7个数了,这里也是同理。 always @(posedge sysclk) begin   if(rst_n == 0) cont <= 0;   else begin     if(cont < Time_1s - 1)  //未计满1s cont <= cont +1;     else //这个else就是对上一个条件的否定,也就是cnt>=Time_1s-1的时候 cont <= 0;        //清0,重复计数   end end always @(posedge sysclk) begin   if(rst_n == 0) led <= 4'b0011;   else    begin     if(cont < Time_1s-1)      //未计满1s led <= led;     else // 这个else就是对上一个条件的否定,也就是cnt>=Time_1s-1的时候 led <= {led[1:0],led[3:2]};  //还可以替换成led<=~led;//按位取反。   end end

学习上下文

产出状态

评优秀3 位工程师
工程师已阅287 位工程师
教务需修改