vhdl课程设计(电子钟+闹铃).docx

上传人:doc321 文档编号:12826347 上传时间:2021-12-06 格式:DOCX 页数:27 大小:292.71KB
返回 下载 相关 举报
vhdl课程设计(电子钟+闹铃).docx_第1页
第1页 / 共27页
vhdl课程设计(电子钟+闹铃).docx_第2页
第2页 / 共27页
vhdl课程设计(电子钟+闹铃).docx_第3页
第3页 / 共27页
vhdl课程设计(电子钟+闹铃).docx_第4页
第4页 / 共27页
vhdl课程设计(电子钟+闹铃).docx_第5页
第5页 / 共27页
亲,该文档总共27页,到这儿已超出免费预览范围,如果喜欢就下载吧!
资源描述

《vhdl课程设计(电子钟+闹铃).docx》由会员分享,可在线阅读,更多相关《vhdl课程设计(电子钟+闹铃).docx(27页珍藏版)》请在三一文库上搜索。

1、.数字钟的设计一、系统功能概述(一)、 系统实现的功能:1、具有 “时 ”、分“”、秒“ ”的十进制数字显示(小时从 00 23 )。2、具有手动校时 、校分 、校秒的功能 。3、有定时和闹钟功能,能够在设定的时间发出闹铃声。4、能进行整点报时。从 59 分 50 秒起 ,每隔 2 秒发一次低音“嘟 ”的信号 ,连续 5 次,最后一次为高音“嘀 ”的信号 。(二)、 各项设计指标 :1、显示部分采用的6 个 LED 显示器 ,从高位至低位分别显示时、分、秒。2、有一个设置调闹钟定时时间、正常时间的按钮,选择调的对象。3、有三个按钮分别调时、分、秒的时间 。4、有一个按钮用作开启/ 关闭闹铃 。

2、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

3、 为计时模块提供时钟信号,每秒计数一次;key_slt 选择设置对象 :定时或正常时间 ;key_alarm 能够开启和关闭闹铃; sec_set 、 min_set 、 hour_set用于设置时间或定时 ,与 key_slt 相关联 。 各按键输出为脉冲信号。( 2)、 CNT60_A_SEC 模块 :这个模块式将clk_1hz 这个时钟信号进行60 进制计数 ,并产生一个分钟的触发信号 。 该模块能将当前计数值实时按BCD 码的格式输出 。 将该输出接到两位LED 数码后能时时显示秒的状态。 通过 alarm_clk 可以选择设置对象为时间还是定时值。在设置时间模式上 , key 上的一

4、个输入脉冲可以将clk的输入信号加一。在设置定时模式上,key 上的脉冲只修改定时值,不影响时间脉冲clk 的状态 。同时该模块具有两个输出口out_do 、 out_di 来触发整点报时的“嘟 ”、嘀“ ”声音 。( 3)、 CNT60_A_MIN 模块 :这个模块式将CNT60_A_SEC 的输出信号进行60 进制计数 ,并产生一个时位的触发信号 。 该模块能将当前计数值实时按BCD 码的格式输出 。 将该输出接到两位LED 数码后能时时显示分的状态。 通过 alarm_clk 可以选择设置对象为时间还是定时值。在设置时间模式上, key 上的一个输入脉冲可以将clk 的输入信号加一。在设

5、置定时模式上, key 上的脉冲只修改定时值,不影响时间脉冲clk 的状态 。同时该模块具有三个输出口out_do 、 out_di 、out_alarm来触发整点报时的“嘟 ”、“嘀 ”、闹铃声音 。.专业专注.( 4)、 CNT24_A_HOUR 模块 :这个模块式将CNT60_A_MIN的输出信号做24 进制计数 。 该模块能将当前计数值实时按 BCD 码的格式输出 。 将该输出接到两位LED 数码后能时时显示时的状态。通过alarm_clk可以选择设置对象为时间还是定时值。在设置时间模式上, key 上的一个输入脉冲可以将clk 的输入信号加一。在设置定时模式上,key 上的脉冲只修改

6、定时值,不影响时间脉冲clk 的状态 。同时该模块具有一个输出口out_alarm来触发整点报时的闹铃声音。( 5)、 PWM_OUT 模块 :该模块为 PWM 产生模块 ,通过 EN 可开启和关闭PWM 输出 。 模块根据 CLK 信号二分频产生的高低音,并组合 ,能输出三种声音状态“嘟 ”、嘀“ ”、闹铃 。而该三种声音要被秒、分、时的输出触发才能输出PWM 。(二) 系统各个模块的VHDL 程序:(1 )、 CNT60_A_SEC 模块:.专业专注.程序源代码如下:library ieee;entity cnt60_a_sec isport(clk,clr,enb: in std_log

7、ic;-clk:时钟输入信号, clr:清零端 , enb :使能端key: in std_logic;- 输入按键脉冲 ,调整闹铃定时或时间alarm_clk: in std_logic;-1:alarm 0:clk- 设置模式选择: 闹铃调节模式、时间调节模式qout_sl: out std_logic_vector(3 downto 0); -显示输出秒的低位qout_sh: out std_logic_vector(3 downto 0);-显示输出秒的高位co: out std_logic; -进位输出 ,触发分计数模块out_do: out std_logic;-在整点报时中输出“

8、嘟”触发信号out_di: out std_logic -在整点报时中输出“嘀 ”触发信号);end;architecture a of cnt60_a_sec issignal qout2_l:std_logic_vector(3 downto 0);.专业专注.signal qout2_h:std_logic_vector(3 downto 0);signal alarm_l:std_logic_vector(3 downto 0);signal alarm_h:std_logic_vector(3 downto 0);signal clk1,clk2,tclk,aclk,ac_slt:

9、std_logic;beginprocess(alarm_clk)- 当 该端口输入一个脉冲时,修改设置模式: 时间调整或闹铃模式切换beginif alarm_clk'event and alarm_clk='1' thenif ac_slt='0' then-如果为定时模式,将改为闹铃模式ac_slt<='1'elseac_slt<='0'end if;end if;end process;process(key,clk,ac_slt)-根据设置模式 ,处理 key 上的脉冲信号beginif ac_slt

10、='0' then -时间调整模式aclk<='0'if clk='1' and key='1' then -clk=1则 tclk<=0 ,通过挖洞方式添加一个脉冲.专业专注.tclk<='0'elsif clk='0' and key='1' then -clk=0,则 tclk<=1, 产生一个高电平,添加一脉冲tclk<='1'elsetclk<=clk;end if;elsif ac_slt='1' the

11、n -闹铃调整模式tclk<=clk;aclk<=key; -key上的脉冲直接修改闹铃定时值end if;end process;process(tclk,clr,enb) -60进制计数 ,个位 、十位放在两个临时变量中,表示秒的状态beginif clr='1' then-clearing works at the state of high voltageqout2_l<="0000"qout2_h<="0000"elsif tclk'event and tclk='1' theni

12、f enb='1' then-enable works at high voltageif qout2_l="1001" and qout2_h="0101" thenqout2_l<="0000"-afullmodeis completedanda carryoutis.专业专注.generatedqout2_h<="0000"elsif qout2_l="1001" thenqout2_l<="0000"qout2_h<=qout2

13、_h+1;elseqout2_l<=qout2_l+1;- in process of countingend if;end if;end if;end process;process(aclk,clr,enb)-修改闹铃的定时值beginif clr='1' then-clearing works at the state of high voltagealarm_l<="0000"alarm_h<="0000"elsif aclk'event and aclk='1' thenif enb=&

14、#39;1' then-enable works at high voltageif alarm_l="1001" and alarm_h="0101" thenalarm_l<="0000"-afullmodeis completedanda carryoutisgenerated.专业专注.alarm_h<="0000"elsif alarm_l="0101" thenalarm_l<="0000"alarm_h<=alarm_h+1;el

15、sealarm_l<=alarm_l+1;- in process of countingend if;end if;end if;end process;process(qout2_l,qout2_h,alarm_l,alarm_h,alarm_clk)-产生进位 ,显示时间或闹铃定时值beginif qout2_l="0000" and qout2_h="0000" thenco<='1'elseco<='0'end if;if ac_slt='0' then -显示时间qout_sl

16、<=qout2_l;qout_sh<=qout2_h;.专业专注.else-显示定时值qout_sh<=alarm_h;qout_sl<=alarm_l;end if;end process;process(qout2_l,qout2_h) -根据秒的状态输出“嘟 ”、嘀“”触发信号beginif qout2_h="0101" thenif qout2_l="0000" thenout_do<='1'elsif qout2_l="0010" thenout_do<='1

17、9;elsif qout2_l="0100" thenout_do<='1'elsif qout2_l="0110" thenout_do<='1'elsif qout2_l="1000" thenout_do<='1'elseout_do<='0'end if;.专业专注.elsif qout2_h="0000" thenif qout2_l="0000" thenout_di<='1'

18、;out_do<='0'elseout_di<='0'end if;elseout_do<='0'out_di<='0'end if;end process;end;( 2 )、 CNT60_A_MIN 模块:library ieee;entity cnt60_a_min is.专业专注.port(clk,clr,enb: in std_logic; -clk:时钟输入信号 , clr :清零端 , enb :使能端key: in std_logic; -输入按键脉冲,调整闹铃定时或时间alarm_clk:

19、 in std_logic; -1:alarm 0:clk- 设置模式选择:闹铃调节模式、时间调节模式qout_ml: out std_logic_vector(3 downto 0); -显示输出分的低位qout_mh: out std_logic_vector(3 downto 0); -显示输出分的高位co: out std_logic; -进位输出 ,触发时计数模块out_alarm:out std_logic;-闹铃触发信号 ,时间到后输出高电平触发闹铃out_do,out_di: out std_logic-在整点报时中输出“嘟”“嘀”触发信号);end;architecture

20、a of cnt60_a_min issignal qout2_l:std_logic_vector(3 downto 0);signal qout2_h:std_logic_vector(3 downto 0);signal alarm_l:std_logic_vector(3 downto 0);signal alarm_h:std_logic_vector(3 downto 0);signal clk1,clk2,tclk,aclk,ac_slt: std_logic;beginprocess(alarm_clk)- 当 该端口输入一个脉冲时,修改设置模式: 时间调整或闹铃模式切.专业专

21、注.换beginif alarm_clk'event and alarm_clk='1' thenif ac_slt='0' then-如果为定时模式,将改为闹铃模式ac_slt<='1'elseac_slt<='0'end if;end if;end process;process(key,clk,ac_slt) -根据设置模式,处理 key 上的脉冲信号beginif ac_slt='0' then -时间调整模式aclk<='0'if clk='1'

22、and key='1' then-clk=1则 tclk<=0 ,通过挖洞方式添加一个脉冲tclk<='0'elsif clk='0' and key='1' then-clk=0,则 tclk<=1, 产生一个高电平,添加一脉冲tclk<='1'else.专业专注.tclk<=clk;end if;elsif ac_slt='1' then -闹铃调整模式tclk<=clk;aclk<=key; -key上的脉冲直接修改闹铃定时值end if;end pr

23、ocess;process(tclk,clr,enb) -60进制计数 ,个位 、十位放在两个临时变量中,表示分的状态beginif clr='1' then-clearing works at the state of high voltageqout2_l<="0000"qout2_h<="0000"elsif tclk'event and tclk='1' thenif enb='1' then-enable works at high voltageif qout2_l=&quo

24、t;1001" and qout2_h="0101" thenqout2_l<="0000"-afullmodeis completedanda carryoutisgeneratedqout2_h<="0000"elsif qout2_l="1001" thenqout2_l<="0000"qout2_h<=qout2_h+1;.专业专注.elseqout2_l<=qout2_l+1;- in process of countingend if;end

25、if;end if;end process;process(aclk,clr,enb) -修改闹铃的定时值beginif clr='1' then-clearing works at the state of high voltagealarm_l<="0000"alarm_h<="0000"elsif aclk'event and aclk='1' thenif enb='1' then-enable works at high voltageif alarm_l="1001

26、" and alarm_h="0101" thenalarm_l<="0000"-afullmodeis completedanda carryoutisgeneratedalarm_h<="0000"elsif alarm_l="0101" thenalarm_l<="0000"alarm_h<=alarm_h+1;else.专业专注.alarm_l<=alarm_l+1;- in process of countingend if;end if;end

27、 if;end process;process(qout2_l,qout2_h,alarm_l,alarm_h,alarm_clk)-产生进位,显示时间或闹铃定时值 of high voltagebeginif qout2_l="0000" and qout2_h="0000" thenco<='1'elseco<='0'end if;if ac_slt='0' thenqout_ml<=qout2_l;qout_mh<=qout2_h;elseqout_mh<=alarm_h

28、;qout_ml<=alarm_l;end if;end process;.专业专注.process(qout2_l,qout2_h,alarm_l,alarm_h)判断定时值与时间值相等,输出闹铃触发信号beginif qout2_l=alarm_l and qout2_h=alarm_h thenout_alarm<='1'elseout_alarm<='0'end if;end process;process(qout2_l,qout2_h) -根据分的状态输出“嘟 ”、嘀“”触发信号beginif qout2_l="1001&

29、quot; and qout2_h="0101" thenout_do<='1'elseout_do<='0'end if;if qout2_l="0000" and qout2_h="0000" thenout_di<='1'elseout_di<='0'.专业专注.end if;end process;end;( 3 )、 CNT24_A_HOUR 模块 :library ieee;entity cnt24_a_hour isport(clk,

30、clr,enb: in std_logic; -clk:时钟输入信号 , clr :清零端 , enb :使能端key: in std_logic; -输入按键脉冲,调整闹铃定时或时间alarm_clk: in std_logic;-1:alarm 0:clk- 设置模式选择:闹铃调节模式、时间调节模式qout_hl: out std_logic_vector(3 downto 0); -显示输出时的低位qout_hh: out std_logic_vector(3 downto 0); -显示输出时的高位co: out std_logic; -进位输出out_alarm:out std_lo

31、gi-闹铃触发信号输出);.专业专注.end;architecture a of cnt24_a_hour issignal qout2_l:std_logic_vector(3 downto 0);signal qout2_h:std_logic_vector(3 downto 0);signal alarm_l:std_logic_vector(3 downto 0);signal alarm_h:std_logic_vector(3 downto 0);signal clk1,clk2,tclk,aclk,ac_slt: std_logic;beginprocess(alarm_clk)

32、- 当 该端口输入一个脉冲时,修改设置模式: 时间调整或闹铃模式切换beginif alarm_clk'event and alarm_clk='1' thenif ac_slt='0' then-如果为定时模式,将改为闹铃模式ac_slt<='1'elseac_slt<='0'end if;end if;end process;process(key,clk,ac_slt) -根据设置模式,处理 key 上的脉冲信号.专业专注.beginif ac_slt='0' then -时间调整模式ac

33、lk<='0'if clk='1' and key='1' then-clk=1则 tclk<=0 ,通过挖洞方式添加一个脉冲tclk<='0'elsif clk='0' and key='1' then-clk=0,则 tclk<=1, 产生一个高电平,添加一脉冲tclk<='1'elsetclk<=clk;end if;elsif ac_slt='1' then- 闹铃调整模式tclk<=clk;aclk<=key;

34、 -key上的脉冲直接修改闹铃定时值end if;end process;process(tclk,clr,enb) -24进制计数 ,个位 、十位放在两个临时变量中,表示时的状态beginif clr='1' then-clearing works at the state of high voltageqout2_l<="0000"qout2_h<="0000".专业专注.elsif tclk'event and tclk='1' thenif enb='1' then-enable

35、 works at high voltageif qout2_l="1001" thenqout2_l<="0000"-afullmodeis completedanda carryoutisgeneratedqout2_h<=qout2_h+1;elsif qout2_l="0011" and qout2_h="0010" thenqout2_l<="0000"qout2_h<="0000"elseqout2_l<=qout2_l+1;- in

36、 process of countingend if;end if;end if;end process;process(aclk,clr,enb) -修改闹铃的定时值beginif clr='1' then-clearing works at the state of high voltagealarm_l<="0000"alarm_h<="0000"elsif aclk'event and aclk='1' then.专业专注.if enb='1' then-enable works

37、 at high voltageif alarm_l="1001" thenalarm_l<="0000"-afullmodeis completedanda carryoutisgeneratedalarm_h<=qout2_h+1;elsif alarm_l="0011" and alarm_h="0010" thenalarm_l<="0000"alarm_h<="0000"elsealarm_l<=alarm_l+1;- in proce

38、ss of countingend if;end if;end if;end process;process(qout2_l,qout2_h,alarm_l,alarm_h,alarm_clk)-产生进位,显示时间或闹铃定时值 of high voltagebeginif qout2_l="0000" and qout2_h="0000" thenco<='1'elseco<='0'.专业专注.end if;if ac_slt='0' thenqout_hl<=qout2_l;qout_hh<=qout2_h;elseqout_hh<=alarm_h;qout_hl<=alarm_l;end if;end process;process(qout2_l,qout2_h,alarm_l,alarm_h)-定时值与时间值相等,则输出闹钟触发信号beginif qout2_l=alarm_l and qout2_h=alarm_h thenout_alarm<='1'elseout_alarm<='0'end if;end process;end;2、系统以及各个模块的仿真波形.专业专注.

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

当前位置:首页 > 社会民生


经营许可证编号:宁ICP备18001539号-1