带有校时功能地数字闹钟.docx

上传人:b****7 文档编号:8761777 上传时间:2023-02-01 格式:DOCX 页数:28 大小:1.26MB
下载 相关 举报
带有校时功能地数字闹钟.docx_第1页
第1页 / 共28页
带有校时功能地数字闹钟.docx_第2页
第2页 / 共28页
带有校时功能地数字闹钟.docx_第3页
第3页 / 共28页
带有校时功能地数字闹钟.docx_第4页
第4页 / 共28页
带有校时功能地数字闹钟.docx_第5页
第5页 / 共28页
点击查看更多>>
下载资源
资源描述

带有校时功能地数字闹钟.docx

《带有校时功能地数字闹钟.docx》由会员分享,可在线阅读,更多相关《带有校时功能地数字闹钟.docx(28页珍藏版)》请在冰豆网上搜索。

带有校时功能地数字闹钟.docx

带有校时功能地数字闹钟

电子课程设计

--带有校时功能的数字闹钟

 

一、设计任务与要求-3-

二、总体框图-3-

三、选择器件-4

四、功能模块-4

1、分频器div_clk模块……………………………………………………………-4

2、秒计时second模块……………………………………………………………-5

3、分计时minute模块……………………………………………………………-7

4、小时计时hour模块……………………………………………………………-8

5、寄存jicun模块………………………………………………………………-10

6、选择时间输出time_show模块………………………………………………-12

7、闹钟响时长控制time_control模块…………………………………………-14

8、闹钟控制naozhong模块………………………………………………………-15

9、扫描seltime模块……………………………………………………………-17

10、数码管显示deled模块………………………………………………………-19

11、3-8译码器decode3_8模块…………………………………………………-20

五、总体设计电路图

1、总体电路原理图……………………………………………………………-22-

2、总体电路仿真图……………………………………………………………-23-

3、管脚分配……………………………………………………………………-24-

4、硬件验证情况………………………………………………………………-24-

六、心得体会26

 

带有校时功能的数字闹钟

一、设计任务与要求

1、具有时、分、秒显示功能,以二十四小时循环计时。

2、具有稳定的校时功能(预置数法),具有调时调分的功能,可调至任意时、分进行校时。

3、具有闹钟功能,实现分/时闹钟设置,闹钟起闹时间为3s-5s,并在此时间段可手动调节。

附加功能:

具有再整点报时功能,整点报时的同时led灯花样显示。

二、总体框图

上图为总体设计框图,主要有计数模块,闹钟模块和扫描译码显示模块组成。

分频器在外部时钟信号的作用下实现分频后将其分频信号分别输出给计数模块和扫描模块。

在分频信号(秒脉冲)作用下计数模块实现计数功能实现24小时计数功能,但其计数功能是在以BCD码形式所记录的。

这就需要扫描电路去扫描计数模块所输出的时间在500HZ脉冲下经过译码器将其译成共阴数码管所对应的二进制数进行显示,最终显示的为24小时时钟。

若有闹钟信号进入时,其闹钟信号经过计数控制有一二进制数经过扫描电路译码电路数码管后,最终显示闹钟时间。

之后闹钟信号无作用后显示时钟信号。

闹钟时间与正常时间相同后外部控制响铃信号控制响铃时间。

外部时间控制信号可控制时间的校验。

 

三、选择器件

1、pc机一台。

2、CPLD/FPGA适配器板:

标准配置EPF10K10LC84-4接口板,下载接口是数字芯片的下载接口(DIGITALJTAG),主要用于CPLD/FPGA芯片的数据下载。

3、实验箱:

装有七段数码管及蜂鸣器等,七段数码管字形及真值表如下

 

七段数码管字形如下:

七段数码管真值表如下:

表1七段数码管真值表、

 

四、功能模块

各个功能模块及作用如下

1)、分频器div_clk模块

其程序如下:

libraryieee;

useieee.std_logic_1164.all;

useieee.std_logic_unsigned.all;

entityclk_divis

port(clk_in:

instd_logic;

div_outa,div_outb:

outstd_logic);

endclk_div;

architectureaofclk_divis

signalfre_na:

integerrange0to50000000;

signalfre_nb:

integerrange0to100000;

signalclk_tmpa:

std_logic;

signalclk_tmpb:

std_logic;

begin

div_outa<=clk_tmpa;

div_outb<=clk_tmpb;

process(clk_in)

begin

iffalling_edge(clk_in)then

iffre_na>49999999then

fre_na<=0;

clk_tmpa<=notclk_tmpa;

else

fre_na<=fre_na+1;

endif;

iffre_nb>99999then

fre_nb<=0;

clk_tmpb<=notclk_tmpb;

else

fre_nb<=fre_nb+1;

endif;

endif;

endprocess;

enda;

该模块实现的功能是分频。

clk_in输入一个50MHZ的脉冲信号,经过分频器后得到一个1HZ的秒脉冲和一个500HZ的脉冲信号。

2)、秒计时second模块

 

其程序如下:

libraryieee;

useieee.std_logic_1164.all;

useieee.std_logic_unsigned.all;

entitysecondis

port(clk,reset,setmin:

instd_logic;

enmin:

outstd_logic;

daout:

outstd_logic_vector(6downto0));

endentitysecond;

architecturefunofsecondis

signalcount:

std_logic_vector(6downto0);

begin

daout<=count;

process(clk,reset,setmin)

begin

if(reset='0')then

count<="0000000";

elsif(setmin='0')then

enmin<=clk;

elsif(clk'eventandclk='1')then

if(count(3downto0)="1001")then

if(count<16#60#)then

if(count="1011001")then

enmin<='1';

count<="0000000";

else

count<=count+7;

endif;

else

count<="0000000";

endif;

elsif(count<16#60#)then

count<=count+1;

enmin<='0'after100ns;

else

count<="0000000";

endif;

endif;

endprocess;

endfun;

该模块的功能是秒计时及分校验(置分)。

reset为复位信号低电平有效。

当有时钟信号(秒脉冲)进来后进行加计数,计数为六十进制。

当计数满59后,下一时钟来临后进位信号—enmin输出一个脉冲信号。

当分校验信号setmin有一脉冲信号进来后,enmin有一脉冲信号。

其仿真图为:

3)、分计时minute模块

 

其程序如下:

Libraryieee;

useieee.std_logic_1164.all;

useieee.std_logic_unsigned.all;

entityminuteis

port(clk,clk1,reset,sethour:

instd_logic;

enhour:

outstd_logic;

daout:

outstd_logic_vector(6downto0));

endentityminute;

architecturefunofminuteis

signalcount:

std_logic_vector(6downto0);

begin

daout<=count;

process(clk,reset,sethour)

begin

if(reset='0')then

count<="0000000";

elsif(sethour='0')then

enhour<=clk1;

elsif(clk'eventandclk='1')then

if(count(3downto0)="1001")then

if(count<16#60#)then

if(count="1011001")then

enhour<='1';

count<="0000000";

else

count<=count+7;

endif;

else

count<="0000000";

endif;

elsif(count<16#60#)then

count<=count+1;

enhour<='0'after100ns;

else

count<="0000000";

endif;

endif;

endprocess;

endfun;

该模块的功能是分计时及时校验(置时)。

reset为复位信号低电平有效。

秒进位信号进入clk作为脉冲信号进行计数,计数为六十进制。

当计数满59后,下一时钟来临后进位信号—enhour输出一个脉冲信号。

当分校验信号sethour有一脉冲信号进来后,enhour有一脉冲信号。

其仿真图为:

 

 

4)小时计时hour模块

 

其程序如下:

libraryieee;

useieee.std_logic_1164.all;

useieee.std_logic_unsigned.all;

entityhourIS

port(clk,reset:

INSTD_LOGIC;

daout:

outstd_logic_vector(5downto0));

endentityhour;

architecturefunofhouris

signalcount:

std_logic_vector(5downto0);

begin

daout<=count;

process(clk,reset)

begin

if(reset='0')then

count<="000000";

elsif(clk'eventandclk='1')then

if(count(3downto0)="1001")then

if(count<16#23#)then

count<=count+7;

else

count<="000000";

endif;

elsif(count<16#23#)then

count<=count+1;

else

count<="000000";

endif;

endif;

endprocess;

endfun;

该模块的功能是小时计时。

reset为复位信号低电平有效。

分进位信号进入clk作为脉冲信号进行计数,计数为二十四进制。

当计数记到二十三,下一个有效脉冲来临后,下一个状态变为零,之后正常计数。

其仿真图为:

 

 

5)、寄存jicun模块

 

其程序如下:

libraryieee;

useieee.std_logic_1164.all;

useieee.std_logic_unsigned.all;

entityjicunis

port(rst,setm,seth:

instd_logic;

mo:

outstd_logic_vector(6downto0);

ho:

outstd_logic_vector(5downto0)

);

endjicun;

architectureoneofjicunis

signalm:

std_logic_vector(6downto0);

signalh:

std_logic_vector(5downto0);

begin

process(rst,setm)

begin

mo<=m;

ifrst='0'then

if(setm'eventandsetm='1')then

if(m(3downto0)="1001")then

if(m<16#60#)then

if(m="1011001")then

m<="0000000";

else

m<=m+7;

endif;

else

m<="0000000";

endif;

elsif(m<16#60#)then

m<=m+1;

elsem<="0000000";

endif;

endif;

endif;

endprocess;

process(rst,seth)

begin

ho<=h;

ifrst='0'then

if(seth'eventandseth='1')then

if(h(3downto0)="1001")then

if(h<16#23#)then

if(h="100011")then

h<="000000";

else

h<=h+7;

endif;

else

h<="000000";

endif;

elsif(h<16#23#)then

h<=h+1;

elseh<="000000";

endif;

endif;

endif;

endprocess;

endone;

该模块的功能是定时及寄存该闹钟时间。

rst为控制闹钟信号输入,rst=‘0’时setm和seth以脉冲信号计数来置入闹钟时间,当setm和seth不变时将其保存,且可以在rst=‘0’时查看闹钟时间。

其输出信号时和分分别用BCD码表示。

其仿真图为:

 

6)、选择时间输出time_show模块

 

其程序如下:

libraryieee;

useieee.std_logic_1164.all;

useieee.std_logic_unsigned.all;

entitytime_showis

port(rst,reset:

instd_logic;

setm:

instd_logic_vector(6downto0);

seth:

instd_logic_vector(5downto0);

mi:

instd_logic_vector(6downto0);

hi:

instd_logic_vector(5downto0);

daouth:

outstd_logic_vector(5downto0);

daoutm:

outstd_logic_vector(6downto0));

endtime_show;

architectureoneoftime_showis

begin

process(reset,rst,setm)

begin

ifreset='0'thendaoutm<="0000000";

elseifrst='1'thendaoutm<=mi;

elsifrst='0'then

daoutm<=setm;

endif;

endif;

endprocess;

process(reset,rst,seth)

begin

ifreset='0'thendaouth<="000000";

elseifrst='1'thendaouth<=hi;

elsifrst='0'then

daouth<=seth;

endif;

endif;

endprocess;

endone;

该模块的功能是选择显示时间是正常时间还是闹钟时间。

reset为复位信号低电平有效。

其中setm和seth分别为寄存器输出的闹钟时间,mi和hi分别为正常时钟时间,rst为选择信号,当rst=‘0’是选择闹钟时间作为输出,否则选择时钟时间作为输出。

daouth和daoutm分别为输出信号的时和分

其仿真图为:

 

7)、闹钟响时长控制time_control模块

 

其程序如下:

libraryieee;

useieee.std_logic_1164.all;

useieee.std_logic_unsigned.all;

entitytime_controlis

port(a1,b1,c1:

instd_logic;

control_out:

outstd_logic_vector(6downto0));

endtime_control;

architectureaoftime_controlis

begin

process(a1,b1,c1)

begin

ifa1='0'thencontrol_out<="0000011";

elsifb1='0'thencontrol_out<="0000100";

elsifc1='0'thencontrol_out<="0000101";

elsecontrol_out<="0000011";

endif;

endprocess;

enda;

该模块的功能是输入声响时长。

a1,b1,c1三个信号控制蜂鸣器响的时间分别为3s、4s、5s,其中a1优先权最高。

其控制的输出control_out为BCD码作为闹钟模块的秒比较控制蜂鸣器响的时间长度。

其仿真图为:

 

8)、闹钟控制naozhong模块

 

其程序如下:

libraryieee;

useieee.std_logic_1164.all;

useieee.std_logic_unsigned.all;

entitynaozhongis

port(setm,mi,ms,q:

instd_logic_vector(6downto0);

seth,hi:

instd_logic_vector(5downto0);

clk:

instd_logic;

speaker:

outstd_logic;

lamp:

outstd_logic_vector(2downto0));

endnaozhong;

architectureoneofnaozhongis

signalspeaker1:

std_logic;

signalspeaker2:

std_logic;

signalcount:

std_logic_vector(1downto0);

signalcount1,count2:

std_logic;

signalh:

std_logic_vector(5downto0);

signalm:

std_logic_vector(6downto0);

begin

speaker<=speaker1orspeaker2;

h<=seth;

m<=setm;

speakera:

process(clk)

begin

speaker1<=count1;

if(clk'eventandclk='1')then

if(mi="0000000")then

if(ms

count1<='1';

else

count1<='0';

endif;

endif;

endif;

endprocessspeakera;

speakerb:

process(setm,seth)

begin

speaker2<=count2;

if(clk'eventandclk='1')then

if((mi=m)and(hi=h))then

if(ms

count2<='1';

elsecount2<='0';

endif;

endif;

endif;

endprocessspeakerb;

lamper:

process(clk)

begin

if(rising_edge(clk))then

if(mi="0000000")then

if(count<="10")then

if(count="00")then

elsif(count="01")then

lamp<="010";

elsif(count="10")then

lamp<="100";

endif;

count<=count+1;

else

count<="00";

endif;

elselamp<="000";

endif;

endif;

endprocesslamper;

endone;

该模块实现三个功能:

闹钟、整点报时、花样显示。

闹钟:

闹钟时间时分seth、setm与正常时钟时间时分hi、mi比较,相等且响控信号q<时钟秒时间ms时蜂鸣器响,由此可控制响的时间长度。

整点报时:

当时钟时间mi为0时即为整点,且响控信号q<时钟秒时间ms时蜂鸣器响,由此可控制响的时间长度。

花样显示:

当整点时lamper灯有一花样显示。

其仿真图为:

 

 

9)、扫描seltime模块

 

其程序如下:

libraryieee;

useieee.std_logic_1164.all;

useieee.std_logic_unsigned.all;

useieee.std_logic_arith.all;

entityseltimeis

port(clk1,reset:

instd_logic;

sec,min:

instd_logic_vector(6downto0);

hour:

instd_logic_vector(5downto0);

daout:

outstd_logic_vector(3downto0);

sel:

outstd_logic_vector(2downto0));

endseltime;

architecturefunofseltimeis

signalcount:

std_logic_vector(2downto0);

begin

sel<=count;

process(clk1,reset)

begin

if(reset='0')then

count<="000";

elsif(clk1'eventandclk1='1')then

if(count>="101")then

count<="000";

else

count<=count+1;

endif;

endif;

casecountis

when"000"=>daout<=sec(3downto0);

when"001"=>daout(3)<='0';

daout(2downto0)<=sec(6downto4);

when"010"=>daout<=min(3downto0);

when"011"=>daout(3)<='0';

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 考试认证 > 财会金融考试

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1