QQ空间 新浪微博 腾讯微博 微信 更多
  

verilog实现红黄蓝三秒灯

代码如下

test.v文件

led.v文件

module test();

wire led_r,led_g,led_b;

reg clk = 0;

always #5 clk <= ~clk;

led c1
(
    .clk(clk),
    .led_r(led_r),
    .led_g(led_g),
    .led_b(led_b)
);
endmodule
View Code
module led
(
    input clk,
    output reg led_r = 0,
    output reg led_g = 0,
    output reg led_b = 0
);
reg[31:0] cnt = 0;  //计数器 

always @(posedge clk)  //
begin
    if(cnt <32'd300*3)
        cnt <= cnt + 1;
    else
        cnt <= 0;
    case(cnt)
    32'd300:
    begin
        led_r <= 1;
        led_b <= 0;
    end
    32'd300*2:
    begin
        led_g <= 1;
        led_r <= 0;
    end
    32'd300*3:
    begin
        led_b <= 1;
        led_g <= 0;
    end
    endcase
end

endmodule
View Code

 

 

下载链接

https://pan.baidu.com/s/1hIuLFWrNn9MFfHEn4PfEzg

测试仿真波形:

posted @ 2018-06-05 17:18  nupt想象之中  阅读(707)  评论(0编辑  收藏  举报