vhdl课程设计电子钟+闹铃样本.docx

上传人:b****8 文档编号:11102388 上传时间:2023-02-25 格式:DOCX 页数:24 大小:161.75KB
下载 相关 举报
vhdl课程设计电子钟+闹铃样本.docx_第1页
第1页 / 共24页
vhdl课程设计电子钟+闹铃样本.docx_第2页
第2页 / 共24页
vhdl课程设计电子钟+闹铃样本.docx_第3页
第3页 / 共24页
vhdl课程设计电子钟+闹铃样本.docx_第4页
第4页 / 共24页
vhdl课程设计电子钟+闹铃样本.docx_第5页
第5页 / 共24页
点击查看更多>>
下载资源
资源描述

vhdl课程设计电子钟+闹铃样本.docx

《vhdl课程设计电子钟+闹铃样本.docx》由会员分享,可在线阅读,更多相关《vhdl课程设计电子钟+闹铃样本.docx(24页珍藏版)》请在冰豆网上搜索。

vhdl课程设计电子钟+闹铃样本.docx

vhdl课程设计电子钟+闹铃样本

数字钟设计

一、系统功能概述

(一)、系统实现功能:

1、具备“时”、“分”、“秒”十进制数字显示(小时从00~23)。

2、具备手动校时、校分、校秒功能。

3、有定期和闹钟功能,可以在设定期间发出闹铃声。

4、能进行整点报时。

从59分50秒起,每隔2秒发一次低音“嘟”信号,持续5次,最后一次为高音“嘀”信号。

(二)、各项设计指标:

1、显示某些采用6个LED显示屏,从高位至低位分别显示时、分、秒。

2、有一种设立调闹钟定期时间、正常时间按钮,选取调对象。

3、有三个按钮分别调时、分、秒时间。

4、有一种按钮用作启动/关闭闹铃。

5、此外需要两个时钟信号来给系统提供脉冲信号,使时钟和闹钟正常工作,分别为1Hz、1kHz脉冲。

二、系统构成以及系统各某些设计

1、系统构造描述//规定:

系统(或顶层文献)构造描述,各个模块(或子程序)功能描述;

(一)系统顶层文献:

1、顶层文献图:

(见下页)

2、各模块解释:

(1)、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有关联。

各按键输出为脉冲信号。

(2)、CNT60_A_SEC模块:

这个模块式将clk_1hz这个时钟信号进行60进制计数,并产生一种分钟触发信号。

该模块能将当前计数值实时按BCD码格式输出。

将该输出接到两位LED数码后能时时显示秒状态。

通过alarm_clk可以选取设立对象为时间还是定期值。

在设立时间模式上,key上一种输入脉冲可以将clk输入信号加一。

在设立定期模式上,key上脉冲只修改定期值,不影响时间脉冲clk状态。

同步该模块具备两个输出口out_do、out_di来触发整点报时“嘟”、“嘀”声音。

(3)、CNT60_A_MIN模块:

这个模块式将CNT60_A_SEC输出信号进行60进制计数,并产生一种时位触发信号。

该模块能将当前计数值实时按BCD码格式输出。

将该输出接到两位LED数码后能时时显示分状态。

通过alarm_clk可以选取设立对象为时间还是定期值。

在设立时间模式上,key上一种输入脉冲可以将clk输入信号加一。

在设立定期模式上,key上脉冲只修改定期值,不影响时间脉冲clk状态。

同步该模块具备三个输出口out_do、out_di、out_alarm来触发整点报时“嘟”、“嘀”、闹铃声音。

(4)、CNT24_A_HOUR模块:

这个模块式将CNT60_A_MIN输出信号做24进制计数。

该模块能将当前计数值实时按BCD码格式输出。

将该输出接到两位LED数码后能时时显示时状态。

通过alarm_clk可以选取设立对象为时间还是定期值。

在设立时间模式上,key上一种输入脉冲可以将clk输入信号加一。

在设立定期模式上,key上脉冲只修改定期值,不影响时间脉冲clk状态。

同步该模块具备一种输出口out_alarm来触发整点报时闹铃声音。

(5)、PWM_OUT模块:

该模块为PWM产生模块,通过EN可启动和关闭PWM输出。

模块依照CLK信号二分频产生高低音,并组合,能输出三种声音状态——“嘟”、“嘀”、闹铃。

而该三种声音要被秒、分、时输出触发才干输出PWM。

(二)系统各个模块VHDL程序:

(1)、CNT60_A_SEC模块:

程序源代码如下:

libraryieee;

useieee.std_logic_1164.all;

useieee.std_logic_unsigned.all;

entitycnt60_a_secis

port(

clk,clr,enb:

instd_logic;--clk:

时钟输入信号,clr:

清零端,enb:

使能端

key:

instd_logic;--输入按键脉冲,调节闹铃定期或时间

alarm_clk:

instd_logic;--1:

alarm0:

clk--设立模式选取:

闹铃调节模式、时间调节模式

qout_sl:

outstd_logic_vector(3downto0);--显示输出秒低位

qout_sh:

outstd_logic_vector(3downto0);--显示输出秒高位

co:

outstd_logic;--进位输出,触发分计数模块

out_do:

outstd_logic;--在整点报时中输出“嘟”触发信号

out_di:

outstd_logic--在整点报时中输出“嘀”触发信号

);

end;

architectureaofcnt60_a_secis

signalqout2_l:

std_logic_vector(3downto0);

signalqout2_h:

std_logic_vector(3downto0);

signalalarm_l:

std_logic_vector(3downto0);

signalalarm_h:

std_logic_vector(3downto0);

signalclk1,clk2,tclk,aclk,ac_slt:

std_logic;

begin

process(alarm_clk)--当该端口输入一种脉冲时,修改设立模式:

时间调节或闹铃模式切换

begin

ifalarm_clk'eventandalarm_clk='1'then

ifac_slt='0'then--如果为定期模式,将改为闹铃模式

ac_slt<='1';

else

ac_slt<='0';

endif;

endif;

endprocess;

process(key,clk,ac_slt)--依照设立模式,解决key上脉冲信号

begin

ifac_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';

else

tclk<=clk;

endif;

elsifac_slt='1'then--闹铃调节模式

tclk<=clk;

aclk<=key;--key上脉冲直接修改闹铃定期值

endif;

endprocess;

process(tclk,clr,enb)--60进制计数,个位、十位放在两个暂时变量中,表达秒状态

begin

ifclr='1'then--clearingworksatthestateofhighvoltage

qout2_l<="0000";

qout2_h<="0000";

elsiftclk'eventandtclk='1'then

ifenb='1'then--enableworksathighvoltage

ifqout2_l="1001"andqout2_h="0101"then

qout2_l<="0000";--afullmodeiscompletedandacarryoutisgenerated

qout2_h<="0000";

elsifqout2_l="1001"then

qout2_l<="0000";

qout2_h<=qout2_h+1;

else

qout2_l<=qout2_l+1;--inprocessofcounting

endif;

endif;

endif;

endprocess;

process(aclk,clr,enb)--修改闹铃定期值

begin

ifclr='1'then--clearingworksatthestateofhighvoltage

alarm_l<="0000";

alarm_h<="0000";

elsifaclk'eventandaclk='1'then

ifenb='1'then--enableworksathighvoltage

ifalarm_l="1001"andalarm_h="0101"then

alarm_l<="0000";--afullmodeiscompletedandacarryoutisgenerated

alarm_h<="0000";

elsifalarm_l="0101"then

alarm_l<="0000";

alarm_h<=alarm_h+1;

else

alarm_l<=alarm_l+1;--inprocessofcounting

endif;

endif;

endif;

endprocess;

process(qout2_l,qout2_h,alarm_l,alarm_h,alarm_clk)--产生进位,显示时间或闹铃定期值

begin

ifqout2_l="0000"andqout2_h="0000"then

co<='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;

endprocess;

process(qout2_l,qout2_h)--依照秒状态输出“嘟”、“嘀”触发信号

begin

ifqout2_h="0101"then

ifqout2_l="0000"then

out_do<='1';

elsifqout2_l="0010"then

out_do<='1';

elsifqout2_l="0100"then

out_do<='1';

elsifqout2_l="0110"then

out_do<='1';

elsifqout2_l="1000"then

out_do<='1';

else

out_do<='0';

endif;

elsifqout2_h="0000"then

ifqout2_l="0000"then

out_di<='1';

out_do<='0';

else

out_di<='0';

endif;

else

out_do<='0';

out_di<='0';

endif;

endprocess;

end;

(2)、CNT60_A_MIN模块:

libraryieee;

useieee.std_logic_1164.all;

useieee.std_logic_unsigned.all;

entitycnt60_a_minis

port(

clk,clr,enb:

instd_logic;--clk:

时钟输入信号,clr:

清零端,enb:

使能端

key:

instd_logic;--输入按键脉冲,调节闹铃定期或时间

alarm_clk:

instd_logic;--1:

alarm0:

clk--设立模式选取:

闹铃调节模式、时间调节模式

qout_ml:

outstd_logic_vector(3downto0);--显示输出分低位

qout_mh:

outstd_logic_vector(3downto0);--显示输出分高位

co:

outstd_logic;--进位输出,触发时计数模块

out_alarm:

outstd_logic;--闹铃触发信号,时间到后输出高电平触发闹铃

out_do,out_di:

outstd_logic--在整点报时中输出“嘟”“嘀”触发信号

);

end;

architectureaofcnt60_a_minis

signalqout2_l:

std_logic_vector(3downto0);

signalqout2_h:

std_logic_vector(3downto0);

signalalarm_l:

std_logic_vector(3downto0);

signalalarm_h:

std_logic_vector(3downto0);

signalclk1,clk2,tclk,aclk,ac_slt:

std_logic;

begin

process(alarm_clk)--当该端口输入一种脉冲时,修改设立模式:

时间调节或闹铃模式切换

begin

ifalarm_clk'eventandalarm_clk='1'then

ifac_slt='0'then--如果为定期模式,将改为闹铃模式

ac_slt<='1';

else

ac_slt<='0';

endif;

endif;

endprocess;

 

process(key,clk,ac_slt)--依照设立模式,解决key上脉冲信号

begin

ifac_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';

else

tclk<=clk;

endif;

elsifac_slt='1'then--闹铃调节模式

tclk<=clk;

aclk<=key;--key上脉冲直接修改闹铃定期值

endif;

endprocess;

process(tclk,clr,enb)--60进制计数,个位、十位放在两个暂时变量中,表达分状态

begin

ifclr='1'then--clearingworksatthestateofhighvoltage

qout2_l<="0000";

qout2_h<="0000";

elsiftclk'eventandtclk='1'then

ifenb='1'then--enableworksathighvoltage

ifqout2_l="1001"andqout2_h="0101"then

qout2_l<="0000";--afullmodeiscompletedandacarryoutisgenerated

qout2_h<="0000";

elsifqout2_l="1001"then

qout2_l<="0000";

qout2_h<=qout2_h+1;

else

qout2_l<=qout2_l+1;--inprocessofcounting

endif;

endif;

endif;

endprocess;

process(aclk,clr,enb)--修改闹铃定期值

begin

ifclr='1'then--clearingworksatthestateofhighvoltage

alarm_l<="0000";

alarm_h<="0000";

elsifaclk'eventandaclk='1'then

ifenb='1'then--enableworksathighvoltage

ifalarm_l="1001"andalarm_h="0101"then

alarm_l<="0000";--afullmodeiscompletedandacarryoutisgenerated

alarm_h<="0000";

elsifalarm_l="0101"then

alarm_l<="0000";

alarm_h<=alarm_h+1;

else

alarm_l<=alarm_l+1;--inprocessofcounting

endif;

endif;

endif;

endprocess;

process(qout2_l,qout2_h,alarm_l,alarm_h,alarm_clk)--产生进位,显示时间或闹铃定期值ofhighvoltage

begin

ifqout2_l="0000"andqout2_h="0000"then

co<='1';

else

co<='0';

endif;

ifac_slt='0'then

qout_ml<=qout2_l;

qout_mh<=qout2_h;

else

qout_mh<=alarm_h;

qout_ml<=alarm_l;

endif;

endprocess;

process(qout2_l,qout2_h,alarm_l,alarm_h)–判断定期值与时间值相等,输出闹铃触发信号

begin

ifqout2_l=alarm_landqout2_h=alarm_hthen

out_alarm<='1';

else

out_alarm<='0';

endif;

endprocess;

process(qout2_l,qout2_h)--依照分状态输出“嘟”、“嘀”触发信号

begin

ifqout2_l="1001"andqout2_h="0101"then

out_do<='1';

else

out_do<='0';

endif;

ifqout2_l="0000"andqout2_h="0000"then

out_di<='1';

else

out_di<='0';

endif;

endprocess;

end;

(3)、CNT24_A_HOUR模块:

libraryieee;

useieee.std_logic_1164.all;

useieee.std_logic_unsigned.all;

entitycnt24_a_houris

port(

clk,clr,enb:

instd_logic;--clk:

时钟输入信号,clr:

清零端,enb:

使能端

key:

instd_logic;--输入按键脉冲,调节闹铃定期或时间

alarm_clk:

instd_logic;--1:

alarm0:

clk--设立模式选取:

闹铃调节模式、时间调节模式

qout_hl:

outstd_logic_vector(3downto0);--显示输出时低位

qout_hh:

outstd_logic_vector(3downto0);--显示输出时高位

co:

outstd_logic;--进位输出

out_alarm:

outstd_logi--闹铃触发信号输出

);

end;

architectureaofcnt24_a_houris

signalqout2_l:

std_logic_vector(3downto0);

signalqout2_h:

std_logic_vector(3downto0);

signalalarm_l:

std_logic_vector(3downto0);

signalalarm_h:

std_logic_vector(3downto0);

signalclk1,clk2,tclk,aclk,ac_slt:

std_logic;

begin

process(alarm_clk)--当该端口输入一种脉冲时,修改设立模式:

时间调节或闹铃模式切换

begin

ifalarm_clk'eventandalarm_clk='1'then

ifac_slt='0'then--如果为定期模式,将改为闹铃模式

ac_slt<='1';

else

ac_slt<='0';

endif;

endif;

endprocess;

process(key,clk,ac_slt)--依照设立模式,解决key上脉冲信号

begin

ifac_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';

else

tclk<=clk;

endif;

elsifac_slt='1'then--闹铃调节模式

tclk<=clk;

aclk<=key;--key上脉冲直接修改闹铃定期值

endif;

endprocess;

process(tclk,clr,enb)--24进制计数,个位、十位放在两个暂时变量中,表达时状态

begin

ifclr='1'then--clearingworksatthestateofhighvoltage

qout2_l<="0000";

qout2_h<="0000";

elsiftclk'eventandtclk='1'then

ifenb='1'then--enableworksathighvoltage

ifqout2_l="1001"then

qout2_l<="0000";--afullmodeiscompletedandacarryoutisgenerated

qou

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

当前位置:首页 > 高等教育 > 经济学

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

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