首页 > 其他分享 >verilog写12 小时时钟(带上午/下午指示器)计数器(HDLbits Count clock)

verilog写12 小时时钟(带上午/下午指示器)计数器(HDLbits Count clock)

时间:2024-06-24 14:01:08浏览次数:3  
标签:Count reset 00 12 59 HDLbits clock output

Create a set of counters suitable for use as a 12-hour clock (with am/pm indicator). Your counters are clocked by a fast-running clk, with a pulse on ena whenever your clock should increment (i.e., once per second).

reset resets the clock to 12:00 AM. pm is 0 for AM and 1 for PM. hh, mm, and ss are two BCD (Binary-Coded Decimal) digits each for hours (01-12), minutes (00-59), and seconds (00-59). Reset has higher priority than enable, and can occur even when not enabled.

The following timing diagram shows the rollover behaviour from 11:59:59 AM to 12:00:00 PM and the synchronous reset and enable behaviour.

比较蠢的方法,无限if嵌套,对着波形改了好久

module top_module(
    input clk,
    input reset,
    input ena,
    output pm,
    output [7:0] hh,
    output [7:0] mm,
    output [7:0] ss); 
    reg [7:0] hh1,mm1,ss1;
    always@(posedge clk)
        begin
        if(reset)
            begin
                ss<=0;
                hh<=8'b00010010;
                mm<=0;
            end
       else if(ena)
                begin
                    if((hh == 8'h11)&&(mm == 8'h59)&&(ss == 8'h59))
                        pm<=~pm;
                    else
                        pm<=pm;
                    if(ss[3:0]==4'd9)
                        begin
                            ss[3:0]<=0;
                            if(ss[7:4]==4'd5&&ss[3:0]==4'd9)
                                begin
                                    ss<=0;
                                    if(mm[3:0]==4'd9)
                                        begin
                                            mm[3:0]<=0;
                                            if(mm[7:4]==4'd5&&mm[3:0]==4'd9)
                                                 begin
                                                     mm<=0;
                                                     if(hh[3:0]==4'd9)
                                                         begin
                                                             hh[3:0]<=4'b0;
                                                             hh[7:4]<=1;
                                                         end
                                                     else if(hh[7:4]==4'd1&&hh[3:0]==4'd2)
                                                           hh<=1;
                                                     else
                                                         hh[3:0]<=hh[3:0]+1'b1;
                                                 end
                                            else
                                                mm[7:4]<=mm[7:4]+1'b1;
                                        end
                                    else
                                        mm[3:0]<=mm[3:0]+1'b1;
                                end
                            else
                                ss[7:4]<=ss[7:4]+1'b1;
                        end
                    else
                        ss[3:0]<=ss[3:0]+1'b1;
                end            
        end
endmodule

标签:Count,reset,00,12,59,HDLbits,clock,output
From: https://blog.csdn.net/zcy000810/article/details/139838691

相关文章

  • HDLBits练习Shift18 Verilog逻辑右移和算数右移的区别
    算术右移时,移入的是移位寄存器中数字(本例中为q[63])的符号位,而不是逻辑右移时的零。右移n位,即加入n位符号位。即若符号位为1,在左边补1;若符号位为0,就补0。算术右移的另一种思路是,它假定被移位的数字是带符号的,并保留符号,因此算术右移是右移n位将带符号的数字除以2的n次幂。......
  • [题解]CF1712E1 LCM Sum (easy version)
    思路这是一道极好的思维题,主要考察了:组合数学和正难则反的方法。这题可以发现如果用直接法将十分的繁琐,于是乎,我们可以用正难则反的方法,即:总的减去不满足的。这道题总的很好求,为:\(C_{r-l+1}^{3}\)。不满足的情况,我们就可以将题目转化为:\(\operatorname{lcm}(i,j,k)<i+......
  • [题解]CF1712D Empty Graph
    思路因为我们枚举的直径是具备单调性的,所以可以使用二分答案。我们可以想一个事情,如果有两个点\(u\)和\(v\),它们两点之间的最短路径要么是直接从\(u\tov\);要么是经过一个中转点\(t\),即:\(u\tot\tov\)。然后,我们可以发现一个显然的规律,就是\(t\)一定是区间\(a\)中......
  • [题解]CF1312E Array Shrinking
    思路本题为P3146变式,也算是一道很经典的区间DP题了。因为\(n\leq500\),考虑区间DP。定义\(dp_{i,j}\)表示操作\([i,j]\)区间剩余长度的最小值。那么,我们可以枚举一个中间值\(k\),可以显然地得到一个状态转移方程(即不能合二为一的情况):\[dp_{i,j}=\min(dp_{i,......
  • [题解]CF1223F Stack Exterminable Arrays
    CCF出的原题观摩一下。思路首先可以用一个Trie来维护。在这里对本文中的一些变量做一下说明。\(p\)表示当前维护的Trie中,指向的元素编号。\(t_i\)表示在Trie中编号为\(i\)的元素在原序列中的值。\(f_i\)表示在Trie中编号为\(i\)的元素在Trie中的父节点。......
  • 'MMDetection3D'+'waymo-open-dataset-tf-2-6-0'+'pytorc2.3.1+cu121'安装
    安装pytorc2.3.1+cu121步骤1.创建并激活一个conda环境condacreate-nmmdpython=3.8-ycondaactivatemmd步骤2.基于PyTorch官方说明安装PyTorch,例如:pip3installtorchtorchvisiontorchaudio--index-urlhttps://download.pytorch.org/whl/cu121步骤3.验......
  • 华为HCIP Datacom H12-821 卷11
    1.多选题OSPF包括哪些报文类型?A、LinkStateDDB、HelloC、LinkStateRequestD、DatabaseDescription正确答案: B,C,D解析:在OSPF协议中,报文类型分为:hello、DD、LSR、LSU、LSAck。所以正确答案是“Hello”、“DatabaseDescription”、“LinkStateRequest”......
  • 【2024-06-12】自我烦恼
    20:00现在我们做中国人要顶勇敢,什么都不怕,什么都顶有决心才好。                                                 ——林徽因昨天一整天,心思都不在工作,打开手机,插着充......
  • localhost 和 127.0.0.1 有什么区别?
    当前端开发人员在本地调试时,他们经常与 localhost 互动,只需运行npmrun命令就可以在浏览器中打开他们的网页,地址栏显示类似于 http://localhost:xxx/index.html的内容。许多人在使用它时可能没有思考两者之间的区别。考虑到我过去与开发人员合作时他们也缺乏对这两者区别......
  • 代码随想录算法训练营第46天 | 121. 买卖股票的最佳时机 、122.买卖股票的最佳时机II
    股票问题是一个动态规划的系列问题,前两题并不难,第三题有难度。买卖股票的最佳时机视频讲解:https://www.bilibili.com/video/BV1Xe4y1u77qhttps://programmercarl.com/0121.买卖股票的最佳时机.html/***@param{number[]}prices*@return{number}*/varmaxProfit=......