Count clock

写了半天不对,才注意到是十六进制的 - -
另外安装了vivado 哈哈哈哈,可以看看写的到底对不对
之前好多程序在 hdlbits 可以正确运行 但是 vivado 编译不通过。

module clock(
    input clk,
    input reset,
    input ena,
    output reg pm,
    output reg[7:0] hh,
    output reg[7:0] mm,
    output reg[7:0] ss); 
    
    wire [2:0]ena_clock;
    
    assign ena_clock[0]= ss==8'h59;
    assign ena_clock[1]= mm==8'h59 && ss==8'h59;
    assign ena_clock[2]= hh==8'h12 && mm==8'h59 && ss==8'h59;
    
    always@(posedge clk)begin
        if (reset)
            {hh,mm,ss,pm} <= {8'h12,8'h0,8'h0,1'b0};
        else begin
            if(ena)begin
                if (hh==8'h11 && ena_clock[1]) pm <= !pm;
                if (ena_clock[0]) ss <= 8'h0; 
                else if (ss[3:0]<8'h9)
                        ss <= ss+1; 
                    else begin
                        ss[3:0] <= 4'b0;
                        ss[7:4] <= ss[7:4]+1;
                    end
                
                if (ena_clock[1]) mm <= 8'h0; 
                else if (mm[3:0]<8'h9) 
                        mm <= mm + ena_clock[0];
                    else begin
                        if (ena_clock[0])begin
                            mm[3:0] <= 4'b0;
                            mm[7:4] <= mm[7:4]+ena_clock[0];
                        end
                    end
                
                if (ena_clock[2]) hh <= 8'h1; 
                else if (hh[3:0]<8'h9)
                    	hh<= hh+ena_clock[1];
                    else begin
                        if (ena_clock[1])begin
                            hh[3:0] <= 4'b0;
                            hh[7:4] <= hh[7:4]+ena_clock[1];
                        end
                    end
                // if (ena_clock[1]) mm <= 8'h0; else mm <= mm+ena_clock[0];
                // if (ena_clock[2]) hh <= 8'h1; else hh <= hh+ena_clock[1];
            end
        end
    end
endmodule
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Certainly! Here's an example of an HTML program that includes a countdown clock: ```html <!DOCTYPE html> <html> <head> <title>Countdown Clock</title> <style> #countdown { font-size: 48px; font-weight: bold; text-align: center; } </style> </head> <body> <div id="countdown"></div> <script> // Set the countdown date var countDownDate = new Date("Oct 1, 2022 12:00:00").getTime(); // Update the countdown every second var countdownTimer = setInterval(function() { // Get the current time var now = new Date().getTime(); // Calculate the time remaining var distance = countDownDate - now; // Calculate the days, hours, minutes, and seconds remaining var days = Math.floor(distance / (1000 * 60 * 60 * 24)); var hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60)); var minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60)); var seconds = Math.floor((distance % (1000 * 60)) / 1000); // Update the countdown display document.getElementById("countdown").innerHTML = days + "d " + hours + "h " + minutes + "m " + seconds + "s "; // If the countdown is finished, display a message if (distance < 0) { clearInterval(countdownTimer); document.getElementById("countdown").innerHTML = "EXPIRED"; } }, 1000); </script> </body> </html> ``` In this program, we first create an HTML div element with the id "countdown" that will display the countdown. We then use JavaScript to set the countdown date (in this example, October 1, 2022 at 12:00:00). We then use the setInterval function to update the countdown every second. In the update function, we calculate the time remaining, calculate the days, hours, minutes, and seconds remaining, and update the "countdown" div to display this information. If the countdown is finished (i.e. the distance is less than 0), we display the message "EXPIRED".
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值