HDLBits / Counters / 12-hour clock 个人思路/自用
要求:
用计数器创建一个12小时制时钟,包括am和pm的指示。clk信号每秒一个脉冲,reset信号将时钟重置到12:00:00AM。pm为0时,实际为AM;pm为1时,实际为PM。hh、mm、ss都是由两个BCD码组成的。reset比enable更加优先。
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.


思路:
1. ss、mm、hh都是由两个bcd码组成的,所以要分成十位和个位,否则会显示成16进制;
2. 分成十位和分位后,就不能使用模60和模12计数器,也可以不用计数器模块,但是这样代码中重复太多,还是选用计数器并引用模块更简洁明了。ss和mm个位改用模10计数器(0-9),十位改用模6计数器(0-5)。因为时十位只有1、0两个状态,所以hh采用if语句直接置数比较方便;
3. 首先写两个计数器并引用模块,注意每位的使能端都是与上一位的输出有关,这是这部分的重点,搞清这个基本就能解决;
4. pm注意都是在11时59分59秒状态发生转换,注意不能直接令pm为!pm,会报错,要先赋成另一个值。
以下就是代码