HDLBits答案

该博客详细介绍了如何使用Verilog设计一个4位二进制编码的十进制计数器(BCD计数器)和一个12小时时钟。4位BCD计数器分别处理个位、十位、百位和千位,每个位都有相应的进位条件。12小时时钟设计中,通过多个计数器模拟秒、分、小时的递增,并处理AM和PM的切换。在时钟达到12:59:59PM时,会自动转换为01:59:59AM。所有计数器都依赖于一个共同的时钟信号,并使用使能信号来控制递增。

HDLBits【学习记录(难点)】

1.4-bit decimal counter

Build a 4-digit BCD (binary-coded decimal) counter. Each decimal digit is encoded using 4 bits: q[3:0] is the ones digit, q[7:4] is the tens digit, etc. For digits [3:1], also output an enable signal indicating when each of the upper three digits should be incremented.
在这里插入图片描述

module top_module (
    input clk,
    input reset,   // Synchronous active-high reset
    output [3:1] ena,
    output [15:0] q);
    assign ena[3:1]={
   
   (q[3:0]==4'd9)&&(q[11:8]==4'd9)&&(q[7:4]==4'd9),(q[7:4]==4'd9)&&(q[3:0]==4'd9),(q[3:0]==4'd9)};
   // assign q={q[15:12],q[11:8],q[7:4],q[3:0]};
    BCD_Decade_Counter Ge_BCD(
        .clk(clk),
        .reset(reset),
        .enable(1'b1),
        .q(q[3:0])
    );
    BCD_Decade_Counter Shi_BCD(
        .clk(clk),
        .reset(reset),
        .enable(ena[1]),
        .q(q[7:4])
    );
    BCD_Decade_Counter Bai_BCD(
        .clk(clk),
        .reset(reset),
        .enabl
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值