数字电路课程设计电子数字钟+闹铃.docx
《数字电路课程设计电子数字钟+闹铃.docx》由会员分享,可在线阅读,更多相关《数字电路课程设计电子数字钟+闹铃.docx(32页珍藏版)》请在冰豆网上搜索。
数字电路课程设计电子数字钟+闹铃
数字电路课程设计
院系:
专业:
电子信息工程姓名:
学号:
完成日期:
2021
数字钟的设计
一、系统功能概述、系统实现的功能:
1、具有“时”、“分”、“秒”的十进制数字显示。
2、具有手动校时、校分、校秒的功能。
3、有定时和闹钟功能,能够在设定的时间发出闹铃声。
4、能进行整点报时。
从59分50秒起,每隔2秒发一次低音“嘟”
的信号,连续5次,最后一次为高音“嘀”的信号。
、各项设计指标:
1、显示部分采用的6个LED显示器,从高位至低位分别显示时、分、秒。
2、有一个设置调闹钟定时时间、正常时间的按钮,选择调的对
象。
3、有三个按钮分别调时、分、秒的时间。
4、有一个按钮用作开启/关闭闹铃。
5、另外需要两个时钟信号来给系统提供脉冲信号,使时钟和闹
二、系统组成以及系统各部分的设计
1、系统结构描述//要求:
系统结构描述,各个模块的功能描述;
系统的顶层文件:
1、顶层文件图:
2、各模块的解释:
、7个输入量clk_1khz、clk_1hz、key_
slt、key_
alarm、sec_
set、min_
set、hour_set:
其中clk_1khz为闹铃模块提供时钟,处理后能产生“嘟”、“嘀”和变化的闹铃声音;
clk_1hz为计时模块提供时钟信号,每秒计数一次;
key_slt选择设置对象:
定时或正常时间;
key_alarm能够开启和关闭闹铃;
sec_
set、min_
set、hour_set用于设置时间或定时,与key_slt相关联。
各按键输出为脉冲信号。
、CNT60_A_SEC模块:
这个模块式将clk_1hz这个时钟信号进行60进制计数,并产生一个分钟的触发信号。
该模块能将当前计数值实时按BCD码的格式输出。
将该输出接到两位LED数码后能时时显示秒的状态。
通过alarm_clk可以选择设置对象为时间还是定时值。
在设置时间模式上,key上的一个输入脉冲可以将clk的输入信号加一。
在设置定时模式上,key上的脉冲只修改定时值,不影响时间脉冲clk的状态。
同时该模块具有两个输出口out_
do、out_di来触发整点报时的“嘟”、“嘀”声音。
、CNT60_A_MIN模块:
这个模块式将CNT60_A_SEC的输出信号进行60进制计数,并产
生一个时位的触发信号。
该模块能将当前计数值实时按BCD码的格式输出。
将该输出接到两位LED数码后能时时显示分的状态。
通过alarm_clk可以选择设置对象为时间还是定时值。
在设置时间模式上,key上的一个输入脉冲可以将clk的输入信号加一。
在设置定时模式上,key上的脉冲只修改定时值,不影响时间脉冲clk的状态。
同时该模块具有三个输出口out_
do、out_
di、out_alarm来触发整点报时的“嘟”、“嘀”、闹铃声音。
、CNT24_A_HOUR模块:
这个模块式将CNT60_A_MIN的输出信号做24进制计数。
该模块能将当前计数值实时按BCD码的格式输出。
将该输出接到两位LED数码后能时时显示时的状态。
通过alarm_clk可以选择设置对象为时间还是定时值。
在设置时间模式上,key上的一个输入脉冲可以将clk的输入信号加一。
在设置定时模式上,key上的脉冲只修改定时值,不影响时间脉冲clk的状态。
同时该模块具有一个输出口out_alarm来触发整点报时的闹铃声音。
、PWM_OUT模块:
该模块为PWM产生模块,通过EN可开启和关闭PWM输出。
模块根据CLK信号二分频产生的高低音,并组合,能输出三种声音状态——“嘟”、“嘀”、闹铃。
而该三种声音要被秒、分、时的输出触
发才能输出PWM。
系统各个模块的VHDL程序:
、CNT60_A_SEC模块:
程序源代码如下:
libraryieee;
use
ieee.std_logic_
1164.all;
use
ieee.std_logic_
unsigned.all;
entitycnt60_a_secisport;
--
显示输出秒的低位qout_
sh:
outstd_logic_vector;--显示输
出秒的高位
co:
outstd_logic;
--进位输出,触发分计数模块
out_
do:
outstd_logic;--在整点报时中输出“嘟”触发信号
out_
di:
outstd_logic--在整点报时中输出“嘀”触发信号);
end;
architectureaofcnt60_a_secissignal
qout2_
l:
std_logic_vector;
signalqout2_
h:
std_logic_vector;
signal
alarm_
l:
std_logic_vector;
signal
alarm_
h:
std_logic_vector;
signalclk1,clk2,tclk,aclk,ac_
slt:
std_logic;
beginprocess--当该端口输入一个脉冲时,修改设置
模式:
时间调整或闹铃模式切换beginifalarm_clk'eventand
alarm_clk='1'thenifac_slt='0'then--如果为定时模式,将改为闹铃模式ac_slt='1';
elseac_slt='0';
end
if;
endif;
endprocess;
process--根据设置模式,处理key上
的脉冲信号beginifac_slt='0'then--时间调整模式aclk='
0';
ifclk='1'andkey='1'then--clk=1则tclk=0,通过挖洞方式添加一个脉冲tclk='0';
elsifclk='0'andkey='
1'then--clk=0,则tclk=1,产生一个高电平,添加一脉冲tclk='
1';
elsetclk=clk;
endif;
elsifac_slt='1'then--
闹铃调整模式tclk=clk;
aclk=key;
--key上的脉冲直接修改
闹铃定时值endif;
endprocess;
process--60进制计数,个
位、十位放在两个临时变量中,表示秒的状态beginifclr='1'
then--clearingworksatthestateofhighvoltage
qout2_l=“0000“;
qout2_h=“0000“;
elsiftclk'eventand
tclk='1'thenifenb='1'then--enableworksathighvoltage
ifqout2_l=“1001“andqout2_h=“0101“then
qout2_l=“0000“;--afullmodeiscompletedandacarryoutis
generated
qout2_h=“0000“;
elsif
qout2_l=“1001“then
qout2_l=“0000“;
qout2_h=qout2_h+1;
else
qout2_l=qout2_l+1;--in
processofcountingendif;
endif;
endif;
endprocess;
process--修改闹铃的定时值beginifclr='1'then--clearing
worksatthestateofhighvoltagealarm_l=“0000“;
alarm_h=“0000“;
elsifaclk'eventandaclk='1'thenif
enb='1'then--enableworksathighvoltage
if
alarm_l=“1001“and
alarm_h=“0101“then
alarm_l=“0000“;--afullmodeiscompletedandacarryoutis
generated
alarm_h=“0000“;
elsifalarm_l=“0101“then
alarm_l=“0000“;
alarm_h=alarm_h+1;
else
alarm_l=alarm_l+1;--in
processofcountingendif;
endif;
endif;
endprocess;
process--产生进位,显示时间或闹铃定时值beginif
qout2_l=“0000“andqout2_h=“0000“thenco='1';
else
co='0';
endif;
ifac_slt='0'then--显示时间
qout_sl=qout2_l;
qout_sh=qout2_h;
else
--显示
定时值qout_sh=alarm_h;
qout_sl=alarm_l;
endif;
end
process;
process--根据秒的状态输出“嘟”、“嘀”触发信号
beginifqout2_h=“0101“thenifqout2_l=“0000“then
out_do='1';
elsifqout2_l=“0010“thenout_do='1';
elsifqout2_l=“0100“then
out_do='1';
elsif
qout2_l=“0110“then
out_do='1';
elsif
qout2_l=“1000“thenout_do='1';
elseout_do='0';
endif;
elsifqout2_h=“0000“then
if
qout2_l=“0000“thenout_di='1';
out_do='0';
else
out_di='0';
endif;
elseout_do='0';
out_di='0';
endif;
endprocess;
end;、CNT60_A_MIN模块:
libraryieee;
use
ieee.std_logic_
1164.all;
use
ieee.std_logic_
unsigned.all;
entitycnt60_a_minisport;
--
显示输出分的低位qout_
mh:
outstd_logic_vector;
--显示输
出分的高位
co:
outstd_logic;
--进位输出,触发时计数模块out_
alarm:
outstd_logic;--闹铃触发信号,时间到后输出高电平触
发闹铃out_do,out_
di:
outstd_logic--在整点报时中输出
“嘟”
“嘀”触发信号);
end;
architectureaofcnt60_a_min
is
signal
qout2_
l:
std_logic_vector;
signal
qout2_
h:
std_logic_vector;
signalalarm_
l:
std_logic_vector;
signal
alarm_
h:
std_logic_vector;
signal
clk1,clk2,tclk,aclk,ac_
slt:
std_logic;
beginprocess--当该
端口输入一个脉冲时,修改设置模式:
时间调整或闹铃模式切换
beginifalarm_clk'eventandalarm_clk='1'thenifac_slt='
0'then--如果为定时模式,将改为闹铃模式ac_slt='1';
elseac_slt='0';
endif;
endif;
endprocess;
process
--根据设置模式,处理key上的脉冲信号beginifac_slt='0'
then--时间调整模式aclk='0';
ifclk='1'andkey='1'
then--clk=1则tclk=0,通过挖洞方式添加一个脉冲tclk='0';
elsifclk='0'andkey='1'then--clk=0,则tclk=1,产生一个
高电平,添加一脉冲tclk='1';
elsetclk=clk;
endif;
elsifac_slt='1'then--闹铃调整模式tclk=clk;
aclk=key;
--key上的脉冲直接修改闹铃定时值endif;
endprocess;
process--60进制计数,个位、十位放在两个临时变量中,表示分
的状态beginifclr='1'then--clearingworksatthestate
ofhighvoltageqout2_l=“0000“;
qout2_h=“0000“;
elsiftclk'eventandtclk='1'thenifenb='1'then--enableworksathighvoltage
ifqout2_l=“1001“and
qout2_h=“0101“then
qout2_l=“0000“;--afullmodeis
completedandacarryoutisgenerated
qout2_h=“0000“;
elsifqout2_l=“1001“then
qout2_l=“0000“;
qout2_h=qout2_h+1;
else
qout2_l=qout2_l+1;--in
processofcountingendif;
endif;
endif;
endprocess;
process--修改闹铃的定时值beginifclr='1'then--clearing
worksatthestateofhighvoltagealarm_l=“0000“;
alarm_h=“0000“;
elsifaclk'eventandaclk='1'thenif
enb='1'then--enableworksathighvoltage
if
alarm_l=“1001“and
alarm_h=“0101“then
alarm_l=“0000“;--afullmodeiscompletedandacarryoutis
generated
alarm_h=“0000“;
elsif
alarm_l=“0101“then
alarm_l=“0000“;
alarm_h=alarm_h+1;
else
alarm_l=alarm_l+1;--in
processofcountingendif;
endif;
endif;
endprocess;
process--产生进位,显示时间或闹铃定时值ofhighvoltagebegin
ifqout2_l=“0000“andqout2_h=“0000“thenco='1';
else
co='0';
endif;
ifac_slt='0'thenqout_ml=qout2_l;
qout_mh=qout2_h;
elseqout_mh=alarm_h;
qout_ml=alarm_l;
endif;
endprocess;
process–判断定时值与时间值相等,输出
闹铃触发信号beginifqout2_l=alarm_landqout2_h=alarm_hthenout_alarm='1';
elseout_alarm='0';
endif;
end
process;
process--根据分的状态输出“嘟”、“嘀”触发信号
beginifqout2_l=“1001“andqout2_h=“0101“then
out_do='1';
elseout_do='0';
endif;
if
qout2_l=“0000“andqout2_h=“0000“thenout_di='1';
elseout_di='0';
endif;
endprocess;
end;、CNT24_A_HOUR
模块:
libraryieee;
use
ieee.std_logic_
1164.all;
use
ieee.std_logic_
unsigned.all;
entitycnt24_a_hourisport;
--
显示输出时的低位qout_
hh:
outstd_logic_vector;
--显示输
出时的高位
co:
outstd_logic;
--进位输出
out_
alarm:
outstd_logi--闹铃触发信号输出);
end;
architectureaofcnt24_a_hourissignal
qout2_
l:
std_logic_vector;
signalqout2_
h:
std_logic_vector;
signal
alarm_
l:
std_logic_vector;
signal
alarm_
h:
std_logic_vector;
signalclk1,clk2,tclk,aclk,ac_
slt:
std_logic;
beginprocess--当该端口输入一个脉冲时,修改设置
模式:
时间调整或闹铃模式切换beginifalarm_clk'eventand
alarm_clk='1'thenifac_slt='0'then--如果为定时模式,将改为闹铃模式ac_slt='1';
elseac_slt='0';
end
if;
endif;
endprocess;
process--根据设置模式,处理key
上的脉冲信号beginifac_slt='0'then--时间调整模式aclk='0';
ifclk='1'andkey='1'then--clk=1则tclk=0,通过挖洞方式添加一个脉冲tclk='0';
elsifclk='0'and
key='1'then--clk=0,则tclk=1,产生一个高电平,添加一脉冲
tclk='1';
elsetclk=clk;
endif;
elsifac_slt='1'
then--闹铃调整模式tclk=clk;
aclk=key;
--key上的脉冲
直接修改闹铃定时值endif;
endprocess;
process--24进制
计数,个位、十位放在两个临时变量中,表示时的状态beginif
clr='1'then--clearingworksatthestateofhighvoltage
qout2_l=“0000“;
qout2_h=“0000“;
elsiftclk'eventand
tclk='1'thenifenb='1'then--enableworksathighvoltage
ifqout2_l=“1001“then
qout2_l=“0000“;--afullmode
iscompletedandacarryoutisgeneratedqout2_h=qout2_h+1;
elsifqout2_l=“0011“andqout2_h=“0010“then
qout2_l=“0000“;
qout2_h=“0000“;
else
qout2_l=qout2_l+1;--inprocessofcountingendif;
end
if;
endif;
endprocess;
process--修改闹铃的定时值begin
ifclr='1'then--clearingworksatthestateofhighvoltage
alarm_l=“0000“;
alarm_h=“0000“;
elsifaclk'eventand
aclk='1'thenifenb='1'then--enableworksathighvoltage
ifalarm_l=“1001“thenalarm_l=“0000“;--afullmode
iscompletedandacarryoutisgeneratedalarm_h=qout2_h+1;
elsifalarm_l=“0011“andalarm_h=“0010“thenalarm_l=“0000“;
alarm_h=“0000“;
else
alarm_l=alarm_l+1;--inprocessofcountingendif;
end
if;
endif;
endprocess;
process--产生进位,显示时间或闹
铃定时值ofhighvoltagebegi