hdlbits:Count clock-12_hour clock 答案参考

 思路:是从秒的后四位开始推,知道时针的十位

module top_module(
    input clk,
    input reset,
    input ena,
    output pm,
    output [7:0] hh,
    output [7:0] mm,
    output [7:0] ss); 
    reg pm_temp;
    wire mmm;
   
    always@(posedge clk)
        if(reset)begin
            ss[3:0]<=0;
    		
            //pm<=0;
        end
    else if(ena==0)
        ss[3:0]<=ss[3:0];
    else if(ss[3:0]==4'd9)
        ss[3:0]<=0;
    else
        ss[3:0]<=ss[3:0]+1'd1;
    
    always@(posedge clk)
        if(reset)
            ss[7:4]<=0;
    		
    else if(ss[3:0]==4'd9&&ss[7:4]<4'd5&&ena==1'd1)
        ss[7:4]<=ss[7:4]+1'd1;
    else if(ss[3:0]==4'd9&&ss[7:4]==4'd5)
        ss[7:4]<=0;
    /*else if(ena==0)
        ss[7:4]<=ss[7:4];*/
    else
        ss[7:4]<=ss[7:4];
    always@(posedge clk)
        if(reset)
            
            mm[3:0]<=0;
            
    else if(ss[3:0]==4'd9&&ss[7:4]==4'd5&&mm[3:0]<4'd9)
        mm[3:0]<=mm[3:0]+1'd1;
    else if(ss[3:0]==4'd9&&ss[7:4]==4'd5&&mm[3:0]==4'd9)
        mm[3:0]<=0;
    else
        mm[3:0]<=mm[3:0];
                    
    always@(posedge clk)
        if(reset)
            mm[7:4]<=0;    
  else if(ss[3:0]==4'd9&&ss[7:4]==4'd5&&mm[3:0]==4'd9&&mm[7:4]<4'd5)
      mm[7:4]<=mm[7:4]+1'd1;
 else if(ss[3:0]==4'd9&&ss[7:4]==4'd5&&mm[3:0]==4'd9&&mm[7:4]==4'd5)
       mm[7:4]<=0;
    else
          mm[7:4]<=mm[7:4];
                    
                    
           always@(posedge clk)
        if(reset)
           
            hh[3:0]<=2;
                    
    else if(ss[3:0]==4'd9&&ss[7:4]==4'd5&&mm[3:0]==4'd9&&mm[7:4]==4'd5&&hh[7:4]==4'd0&&hh[3:0]<4'd9)
       hh[3:0]<=hh[3:0]+1'b1;
    else if(ss[3:0]==4'd9&&ss[7:4]==4'd5&&mm[3:0]==4'd9&&mm[7:4]==4'd5&&hh[7:4]==1'd1&&hh[3:0]<4'd2)
        hh[3:0]<=hh[3:0]+1'b1;
                    else if(ss[3:0]==4'd9&&ss[7:4]==4'd5&&mm[3:0]==4'd9&&mm[7:4]==4'd5&&hh[3:0]==4'd2&&hh[7:4]==4'd1)
                        hh[3:0]<=1'd1;
    else if(ss[3:0]==4'd9&&ss[7:4]==4'd5&&mm[3:0]==4'd9&&mm[7:4]==4'd5&&hh[3:0]==4'd9)
        hh[3:0]<=0;
                    else
                        hh[3:0]<=hh[3:0];
                    
		always@(posedge clk)
        if(reset)
           
            hh[7:4]<=1;
            
    else if(ss[3:0]==4'd9&&ss[7:4]==4'd5&&mm[3:0]==4'd9&&mm[7:4]==4'd5&&hh[3:0]==4'd9&& hh[7:4]==4'd0)
                        hh[7:4]<=hh[7:4]+1'd1;
       						 
    else if(ss[3:0]==4'd9&&ss[7:4]==4'd5&&mm[3:0]==4'd9&&mm[7:4]==4'd5&&hh[3:0]==4'd2&&hh[7:4]==4'd1)
        hh[7:4]<=1'd0;
                    else
                        hh[7:4]<=hh[7:4];
    always@(posedge clk)
        if(reset)
            pm_temp<=0;
    else if(mmm)
        pm_temp<=~pm_temp;
    assign mmm = ss[3:0]==4'd9&&ss[7:4]==4'd5&&mm[3:0]==4'd9&&mm[7:4]==4'd5&&hh[3:0]==4'd1&&hh[7:4]==4'd1;
    assign pm=pm_temp;
endmodule

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值