搭建网站 软件下载,凡科网做的网站能直接用吗,wordpress前台加速,韩城建设局网站忽如一夜春风来#xff0c;千树万树梨花开 —— 《白雪歌诵武判官归京》 岑参 【唐】 目录
简易数字钟
要点剖析#xff1a; 逐步分析#xff1a;
端口说明#xff1a;
代码展示#xff1a;
分部解释#xff1a;
代码编译结果#xff1a;
提醒 #xff1a;
…忽如一夜春风来千树万树梨花开 —— 《白雪歌诵武判官归京》 岑参 【唐】 目录
简易数字钟
要点剖析 逐步分析
端口说明
代码展示
分部解释
代码编译结果
提醒
仿真实例
仿真结果
编辑
求一个免费的赞也可以点一点关注十分感谢
简易数字钟代码和PPT 通过网盘分享的文件简易数字钟.zip 链接: https://pan.baidu.com/s/1oQ3v6up_G5D2VKsISCRmBQ?pwd0406 提取码: 0406 为大家带来数电课设简易数字钟的教程。本教程基于Quartus Ⅱ来编写代码进行仿真。文章内有代码仿真报告答辩PPT按需自取。
简易数字钟 大家先看一看上面的题目和其要求实现的功能。
要点剖析
利用quartus软件基于VHDL语言来编写。时分秒三个计数器分别是二十四进制计数器和六十进制计数器。闹钟功能并且设定时间到时间鸣叫30秒。具有整点报时功能到预定时间鸣叫10秒。完成仿真具有基本功能。 逐步分析
1.对于这一点大家从b站找教程或者某宝找人远程下载对于vhdl语言大家可以自行学习这个课设需要的代码造诣不高大家完全可以自学相较于C就十分简单了。
2.计时器VHDL代码内有基本的语法结构我们只需要知道二十四位计数器需要五位二进制数六十进制计数器需要六位二进制数这就ok了。
3.闹钟功能这个就需要我们独立设计逻辑。
4.整点报时基本和闹钟功能有着类似的代码逻辑大家看后续代码。
5.仿真大家就利用软件内置的来做。
端口说明 代码展示
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;entity Simple_Clock isport(clk : in std_logic; reset : in std_logic;set_alarm : in std_logic;alarm_time_sec : in std_logic_vector(5 downto 0);alarm_time_min : in std_logic_vector(5 downto 0);alarm_time_hour : in std_logic_vector(4 downto 0);alarm_out : out std_logic;chime_out : out std_logic;sec_out : out std_logic_vector(5 downto 0);min_out : out std_logic_vector(5 downto 0);hour_out : out std_logic_vector(4 downto 0));
end entity Simple_Clock;architecture Behavioral of Simple_Clock issignal sec_count : unsigned(5 downto 0) : (others 0);--六位无符号数初始全为0signal min_count : unsigned(5 downto 0) : (others 0);signal hour_count : unsigned(4 downto 0) : (others 0);signal alarm_active : std_logic : 0;--表示闹钟是否激活signal chime_active : std_logic : 0;--表示整点报时是否激活signal alarm_timer : unsigned(4 downto 0) : (others 0);--闹钟激活后的计时signal chime_timer : unsigned(3 downto 0) : (others 0);signal alarm_time_sec_u : unsigned(5 downto 0);--类型转换为无符号的数signal alarm_time_min_u : unsigned(5 downto 0);signal alarm_time_hour_u : unsigned(4 downto 0);
begin-- 转换输入为unsigned类型alarm_time_sec_u unsigned(alarm_time_sec);alarm_time_min_u unsigned(alarm_time_min);alarm_time_hour_u unsigned(alarm_time_hour);-- 秒计数器process(clk, reset)--上下限beginif reset 1 then-- 重置所有信号sec_count (others 0);min_count (others 0);hour_count (others 0);alarm_active 0;chime_active 0;alarm_timer (others 0);chime_timer (others 0);elsif rising_edge(clk) then-- 秒计数逻辑if sec_count 59 thensec_count (others 0);if min_count 59 thenmin_count (others 0);if hour_count 23 thenhour_count (others 0);elsehour_count hour_count 1;end if;elsemin_count min_count 1;end if;elsesec_count sec_count 1;end if;-- 闹钟逻辑if alarm_active 1 and alarm_timer 30 then--如果激活闹钟那么闹钟计时小于30秒则加一响铃一段时间alarm_timer alarm_timer 1;elsif alarm_timer 30 then--大于三十则清零便于下次计时alarm_active 0;alarm_timer (others 0);end if;-- 整点报时逻辑if chime_active 1 and chime_timer 10 thenchime_timer chime_timer 1;elsif chime_timer 10 thenchime_active 0;--关闭计时状态chime_timer (others 0);end if;-- 激活闹钟和整点报时if set_alarm 1 and sec_count alarm_time_sec_u and min_count alarm_time_min_u and hour_count alarm_time_hour_u thenalarm_active 1;--启动闹钟alarm_timer (others 0);elsif sec_count 0 and min_count 0 then--分秒为零意味着整点chime_active 1;chime_timer (others 0);end if;end if;end process;-- 输出信号alarm_out alarm_active;chime_out chime_active;sec_out std_logic_vector(sec_count);min_out std_logic_vector(min_count);hour_out std_logic_vector(hour_count);
end architecture Behavioral;
分部解释
-- 秒计数器process(clk, reset)--上下限beginif reset 1 then-- 重置所有信号sec_count (others 0);min_count (others 0);hour_count (others 0);alarm_active 0;chime_active 0;alarm_timer (others 0);chime_timer (others 0);elsif rising_edge(clk) then这里首先编写了一个关于清零的功能类似于函数但是并不调用
是全部清零包括闹钟的计时时钟的计时都是会清零的类似于恢复出厂设置-- 秒计数逻辑if sec_count 59 thensec_count (others 0);if min_count 59 thenmin_count (others 0);if hour_count 23 thenhour_count (others 0);elsehour_count hour_count 1;end if;elsemin_count min_count 1;end if;elsesec_count sec_count 1;end if;这就是计时功能的相关代码我们编写了计时功能只要秒钟累加到59那么下一次就会分钟加1只要分钟累加到59那么就会时钟加1。如果时钟累加到23那么就会清零。-- 闹钟逻辑if alarm_active 1 and alarm_timer 30 then--如果激活闹钟那么闹钟计时小于30秒则加一响铃一段时间alarm_timer alarm_timer 1;elsif alarm_timer 30 then--大于三十则清零便于下次计时alarm_active 0;alarm_timer (others 0);end if;-- 整点报时逻辑if chime_active 1 and chime_timer 10 thenchime_timer chime_timer 1;elsif chime_timer 10 thenchime_active 0;--关闭计时状态chime_timer (others 0);end if;两个功能的逻辑十分相似都有一个置1且相关计时小于我们要求响铃的时长闹钟 30报时 10那么就会响铃一段时间如果功能内部的timer大于要求响铃的时长那么timer就会清零便于我们下一次使用-- 激活闹钟和整点报时if set_alarm 1 and sec_count alarm_time_sec_u and min_count alarm_time_min_u and hour_count alarm_time_hour_u thenalarm_active 1;--启动闹钟alarm_timer (others 0);elsif sec_count 0 and min_count 0 then--分秒为零意味着整点chime_active 1;chime_timer (others 0);end if;end if;end process;激活闹钟首先要set_alarm 1然后给闹钟制定时间到时间就会自动响铃。
激活整点报时我们不需要set这个逻辑因为整点报时是一直开着的当分和秒为零那么就意味着整点即可以响铃
代码编译结果 提醒
清零之后闹钟会响铃这是因为我的代码中设置了在清零后闹钟响铃的程序只要在闹钟打开的时间内清零闹钟在清零结束后就会响铃。我认为是有用的也可以当作防伪标志。
仿真实例 定时闹钟在45分时响铃。
仿真结果 大家可以看一看ppt从中可以找到更多细节。
求一个免费的赞也可以点一点关注十分感谢