前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >HDLBits Count Clock

HDLBits Count Clock

原创
作者头像
Player
修改2022-07-18 00:10:24
7090
修改2022-07-18 00:10:24
举报
文章被收录于专栏:Xilinx
代码语言:javascript
复制
module top_module(
    input clk,
    input reset,
    input ena,
    output pm,
    output [7:0] hh,
    output [7:0] mm,
    output [7:0] ss);

    wire em;
    wire eh;
    
    assign em = (ss == 8'h59) & ena;
    assign eh = (ss == 8'h59) & (mm == 8'h59) & ena;
    
    ms60 s60(clk, reset, ena, ss);
    ms60 m60(clk, reset, em, mm);   
    h12 h(clk, reset, eh, hh, pm);
    
endmodule

module h12(
    input clk,
    input reset,
    input ena,
    output [7:0] h,
    output reg pm
);
    
    always@(posedge clk)begin
        if(reset)begin
            h <= 8'h12;
            pm <= 0;
        end else begin
            if(ena)begin
                case(h)
                    8'h09:begin
                        h <= 8'h10;
                    end
                    8'h11:begin
                        h <= h + 1;
                        pm <= ~pm;
                    end
                    8'h12:begin
                        h <= 8'h01;
                    end
                    default:begin
                        h <= h + 1;
                    end         
                endcase
            end
        end
    end
    
endmodule

module ms60(
    input clk,
    input reset,
    input ena,
    output [7:0] ms);
    
    bcd #(.M(4'd9)) l(clk, reset, ena, ms[3:0]);
    bcd #(.M(4'd5)) h(clk, reset, (ms[3:0] == 4'd9) & ena, ms[7:4]);
    
endmodule

module bcd
    #(parameter M = 4'd9)
(
    input clk,
    input reset,
    input ena,
    output [3:0] out
);
    
    always@(posedge clk)begin
        if(reset)begin
            out <= 0;
        end else begin
            if(ena)begin
                if(out < M)out <= out + 1;
                else out <= 0;
            end
        end
    end
    
endmodule

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档