Verilog HDL小练习

5s内15Hz4个LED闪烁,再两秒熄灭,循环往复。
引入en,可以使得4个LED灯全亮,以及恢复周期变化。

module led(clk_27MHZ, en, led1, led2, led3, led4);

input clk_27MHZ, en;
output reg led1, led2, led3, led4;
reg[25:0] counter_15HZ;
reg[25:0] counter_1HZ;
reg[3:0]  count_5s, count_7s;
reg       clk_15HZ;
reg       clk_1HZ;

always@(posedge clk_27MHZ) begin
    if(counter_15HZ <= 899999) begin
        counter_15HZ <= counter_15HZ+1;
    end
    else begin
        counter_15HZ <= 0;
        clk_15HZ <= ~clk_15HZ;
    end

    if(counter_1HZ <= 13499999) begin
        counter_1HZ <= counter_1HZ+1;
    end
    else begin
        counter_1HZ <= 0;
        clk_1HZ <= ~clk_1HZ;
    end
end

always@(posedge clk_1HZ, posedge en) begin
    if(en) begin
        {led1, led2, led3, led4} <= 'b1111;
    end
    else begin
            if(count_5s <= 4) begin
                count_5s <= count_5s+1;
                count_7s <= count_7s+1;
                if(clk_15HZ) begin
                    {led1, led2, led3, led4} <= 'b1111;
                end
                else begin
                    {led1, led2, led3, led4} <= 'b0000;
                end
            end
            else begin
                count_7s <= count_7s+1;
                {led1, led2, led3, led4} <= 'b0000;
                if(count_7s == 6) begin
                    count_7s <= 0;
                    count_5s <= 0;
                end
            end
    end
end
endmodule
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值