1、题目:数字钟设计题目:数字钟设计 一、实验目的一、实验目的 学习并掌握数字钟的原理、设计方法。 二、实验内容二、实验内容 计数时钟由模 60 秒计数器、模 60 分计数器、模 24 小时计数器、报时模块、分、时校 定模块及输出显示模块构成。可以采用同步计数器或异步计数器设计方法。 三、实验要求三、实验要求 1. 计时范围为 0 小时 0 分 0 秒至 23 小时 59 分 59 秒 2. 采用 6 个 8 段数码管分别显示小时十位,小时个位、分钟十位、分钟个位、秒十位、 秒个位。 3. 整点报时,蜂鸣器响 5 声,每秒 1 声。 4. 校时功能,能够单独校分、校时。用按键控制。 5. 具有清零
2、、启动/停止计数的功能。用按键控制。 四、实验原理四、实验原理 数字钟的基本原理是采用时钟源提供的频率作为秒模块的时钟进行计数,当秒模块计 数达到 59 秒时为分模块提供时钟,该时钟通过状态选择模块送到分模块,同理,分模块向 小时模块提供时钟时也是如此。整点报时模块是利用分钟向小时的进位时钟脉冲作为触发 源, 利用秒的个位计时以及实验板提供的时钟源频率达到报时五秒的目的。 译码显示模块则 通过 8421BCD 码与数码管各段的关系进行转化, 由于实验板不支持动态扫描所以需在秒, 分, 时的个位与十位都添加译码显示模块。 原理框图如下: 时钟源 秒模块 分模块 状态选择 模块 时模块 状态选择
3、模块 暂停信号 调分模块 数码管 数码管 数码管 报时模 块 五、模块设计五、模块设计 1、 秒计数模块 library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity second is port(clk,rst:in std_logic; enmin:out std_logic; shiwei:out std_logic_vector(3 downto 0); gewei:out std_logic_vector(3 downto 0); end entity second; archit
4、ecture rtl of second is signal a,b:std_logic_vector(3 downto 0); signal c:std_logic_vector(7 downto 0); begin c=b process(clk,rst,c) begin if(rst=1)then a=“0000“; b=“0000“; enmin=0; elsif(clkevent and clk=1)then a=a+1; if(a=“1001“)then a=“0000“; b=b+1; if(b=“0101“)then benminenmin=null; end case; en
5、d process; gewei=a; shiwei=b; end architecture rtl; 其模块仿真图为: clk rst enmin shiwei30 gewei30 second inst1 2、 分计数模块 library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity minute is port(clk,rst:in std_logic; enhour:out std_logic; mshiwei:out std_logic_vector(3 downto 0); mg
6、ewei:out std_logic_vector(3 downto 0); end entity minute; architecture rtl of minute is signal m,n:std_logic_vector(3 downto 0); signal c:std_logic_vector(7 downto 0); begin c=n process(clk,rst,c) begin if(rst=1)then m=“0000“; n=“0000“; enhour=0; elsif(clkevent and clk=1)then m=m+1; if(m=“1001“)then m=“0000“; n=n+1; end if; end if; if(c=“01011001“)then n=“0000“; menhourenhour=null; end case; end process; mgewei=m; mshiwei=n; end architecture rtl; 其模块仿真