产生第八个脉冲时,数字钟恢复时分秒的显示。
闹钟功能是在正常计数功能上拓展,分为闹钟时间预置和闹钟响应两个部分。闹钟时间预置功能:当set1连续产生脉冲时,依次对闹钟的时分秒位进行预置。以upclk为时钟,通过up对预置位进行控制,当up为高时且upclk有脉冲到来时,预置位加一,否则减一。当set1产生第四个脉冲时,数字钟恢复时分秒的显示。与此同时在程序中增添变量时计时功能可以持续运行。闹钟响应功能:通过预置后,储存的变量与计时器模块的时、分、秒进行比对,当时、分、秒相同时,模块产生一个一段时间的高电平,传输给闹钟响应模块。 整点报时功能:当计数器中的分位等于59,秒位等于59时,模块产生一段高电平,输出给扬声器模块进行报时。
(3)年月日计数模块分为年月日计数功能,年月日预置数功能。 年月日计数功能:以时位的进位脉冲为计时脉冲,闰年二月份为29天,普通年二月份为28天。一月、三月、五月、七月、八月、十月、十二月为31天,四月、六月、九月、十一月为30天。 年月日预置数功能:当set产生第一个脉冲后,依次进行年月日数器置数。以upclk为时钟,通过up对预置位进行控制,当up为高时且upclk有脉冲到来时,预置位加一,否则减一。
(4) 显示模块:以时分秒,年月日模块的输出、状态标志为输入信号,通过状态控制模块产生的状态标志对显示模块进行控制,显示计时、预置时的不同状态。
(5)扬声器模块:输入信号为分位、秒位和状态信号,当计时时钟到
达整点是输出高电平,其他时刻输出低电平。
(6)脉冲产生模块:对输入的信号进行1000分频,产生周期为一秒的时钟信号,用于数字钟的时钟输入。
3.2系统结构框图
3.3设计思路与方法 3.3.1 状态控制模块
状态控制模块实现对各个功能模块的整体设计,包括对时间与日期的显示与调整,闹钟的显示与调整等控制操作。状态机的输入为setpin,setpin1,upclk。状态机的状态有11种状态。g0:闹钟设置时位; g1:闹钟设置分位; g2:闹钟设置秒位;
s0:时钟显示时分秒;s1:时钟显示年月日; s2:钟设置年; s3:时钟设置月; s4:时钟设置日; s5:时钟设置时; s6:时钟设置分; s7:设置秒
在产生如上状态的同时产生Tlock,flag状态标志,此标志用来进
行时钟设置、闹钟设置与显示控制。 RTL 电路图
实现代码如下: process(upclk) begin
if (upclk='1' and upclk'LAST_VALUE='0')then state<=next_state; -- 实现状态变换 end if; end process;
process(state,setpin,setpin1) begin
next_state<=state; case(state) is when s0 => Tlock<=\ flag<='1'; if(setpin1='1'
and
setpin1'LAST_VALUE='0')then
next_state<=g0; end if; if(setpin='1'
and
setpin'LAST_VALUE='0')
then
next_state<=s1; end if; when s1=> Tlock<=\ flag<='1'; if(setpin1='1' and
next_state<=g0;end if; if(setpin='1'
and
next_state<=s2;end if; when s2=> Tlock<=\ flag<='1'; if(setpin1='1' and
next_state<=g0;end if; if(setpin='1'
and
next_state<=s3;end if; when s3=> Tlock<=\ flag<='1'; if(setpin1='1' and
next_state<=g0;end if;
setpin1'LAST_VALUE='0')then
then
setpin1'LAST_VALUE='0')then
setpin'LAST_VALUE='0')
then
setpin1'LAST_VALUE='0')then
setpin'LAST_VALUE='0')
if(setpin='1' and next_state<=s4;end if; when s4=> Tlock<=\ flag<='1'; if(setpin1='1' and
next_state<=g0;end if; if(setpin='1'
and
next_state<=s5;end if; when s5=> Tlock<=\ flag<='1'; if(setpin1='1' and
next_state<=g0;end if; if(setpin='1'
and
next_state<=s6; end if; when s6=> Tlock<=\ flag<='1'; if(setpin1='1' and
next_state<=g0;end if; if(setpin='1'
and
setpin'LAST_VALUE='0') then
setpin1'LAST_VALUE='0')then
then
setpin1'LAST_VALUE='0')then
then
setpin1'LAST_VALUE='0')then
then
setpin'LAST_VALUE='0')
setpin'LAST_VALUE='0')
setpin'LAST_VALUE='0')