题目来源于:
https://hdlbits.01xz.net/wiki/Count_clockhdlbits.01xz.net前言:
新手入门,以下内容主要记录学习过程,便于后期改正。新人对语法、结构理解还欠缺,欢迎指出。
进入正题:
题目描述:
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.

大概意思:使用计数器设计一个12小时制的时钟。要求使用BCD,即至少使用4位二进制码表示1位十进制数。
(Binary-Coded Decimal缩写)baike.baidu.com
提示:11:59:59 PM 到12:00:00 AM和从12:59:59 PM到01:00:00 PM的变化。
我的思路:
注意是12小时制的时钟,注意上面的提示部分。
秒和分格式固定,个位从0计到9,十位从0计到5。(00-59)计数到59向上进位一次。
因此,先写一个计数模块,秒和分的计数直接例化。(注:计数模块参考了明德扬书里面得写法)。
小时部分需要注意条件的判断,以及AM,PM状态切换,因此这部分计数单独拎出来写。我就按照逻辑直接写了,应该可以优化简洁。欢迎有更好的方法评论留言。
module