赞
踩
名称:多功能数字钟VHDL代码Quartus仿真(文末获取)
软件:Quartus
语言:VHDL
代码功能:
多功能数字钟
(1)能进行正常的时、分、秒计时,分别用6个七段数码管动态扫描显示时、分、秒的十位和个位
(2)利用按键开关快速调整时间:时、分
(3)通过按键开关设定闹铃时间,到了设定时间发出提示音,提示音长度为1分钟
(4)通过按键开关设定倒计时的时间,通过开关启动倒计时,倒计时为0时发出提示音,提示音长度为1分钟
(5)通过开关控制秒表的开始和结束
1. 工程文件
2. 程序文件
3. 程序编译
4. RTL图
5. 仿真图
分频模块
按键模块
模式控制模块
计时模块
闹钟模块
秒表模块
响铃模块(LED代表响铃)
倒计时模块
显示模块
部分代码展示:
LIBRARY ieee; USE ieee.std_logic_1164.all; ENTITY Digital_clock IS PORT ( clk_50M : IN STD_LOGIC;--时钟 key_0 : IN STD_LOGIC;--模式设置按键--4'd0:计时,4'd1:闹钟,4'd2:跑表,4'd3:定时 key_1 : IN STD_LOGIC;--设置修改,跑表启动 key_2 : IN STD_LOGIC;--修改确认,跑表暂停 key_3 : IN STD_LOGIC;--修改时分秒,跑表复位,闹钟关闭 bell_out : OUT STD_LOGIC; led_mode : OUT STD_LOGIC_VECTOR(3 DOWNTO 0);--led显示当前模式 HEX5 : OUT STD_LOGIC_VECTOR(7 DOWNTO 0);--数码管段选 HEX4 : OUT STD_LOGIC_VECTOR(7 DOWNTO 0);--数码管段选 HEX3 : OUT STD_LOGIC_VECTOR(7 DOWNTO 0);--数码管段选 HEX2 : OUT STD_LOGIC_VECTOR(7 DOWNTO 0);--数码管段选 HEX1 : OUT STD_LOGIC_VECTOR(7 DOWNTO 0);--数码管段选 HEX0 : OUT STD_LOGIC_VECTOR(7 DOWNTO 0)--数码管段选 ); END Digital_clock; ARCHITECTURE behave OF Digital_clock IS --模块声明 --响铃模块 COMPONENT Bell IS PORT ( clk_50M : IN STD_LOGIC; clear_alarm : IN STD_LOGIC; alarm_hour_time : IN STD_LOGIC_VECTOR(7 DOWNTO 0); alarm_minute_time : IN STD_LOGIC_VECTOR(7 DOWNTO 0); alarm_second_time : IN STD_LOGIC_VECTOR(7 DOWNTO 0); hour_time : IN STD_LOGIC_VECTOR(7 DOWNTO 0); minute_time : IN STD_LOGIC_VECTOR(7 DOWNTO 0); second_time : IN STD_LOGIC_VECTOR(7 DOWNTO 0); countdown_hour_time : IN STD_LOGIC_VECTOR(7 DOWNTO 0); countdown_minute_time : IN STD_LOGIC_VECTOR(7 DOWNTO 0); countdown_second_time : IN STD_LOGIC_VECTOR(7 DOWNTO 0); bell_out : OUT STD_LOGIC ); END COMPONENT; --闹钟模块 COMPONENT alarm_clock IS PORT ( clk_50M : IN STD_LOGIC; state_mode : IN STD_LOGIC_VECTOR(3 DOWNTO 0); set_time_key : IN STD_LOGIC; confirm_key : IN STD_LOGIC; change_time_key : IN STD_LOGIC; alarm_hour_time : OUT STD_LOGIC_VECTOR(7 DOWNTO 0); alarm_minute_time : OUT STD_LOGIC_VECTOR(7 DOWNTO 0); alarm_second_time : OUT STD_LOGIC_VECTOR(7 DOWNTO 0) ); END COMPONENT; --显示模块 COMPONENT display IS PORT ( clk : IN STD_LOGIC; state_mode : IN STD_LOGIC_VECTOR(3 DOWNTO 0); alarm_hour_time : IN STD_LOGIC_VECTOR(7 DOWNTO 0); alarm_minute_time : IN STD_LOGIC_VECTOR(7 DOWNTO 0); alarm_second_time : IN STD_LOGIC_VECTOR(7 DOWNTO 0); stopwatch_Millisecond : IN STD_LOGIC_VECTOR(7 DOWNTO 0); stopwatch_second : IN STD_LOGIC_VECTOR(7 DOWNTO 0); stopwatch_minute : IN STD_LOGIC_VECTOR(7 DOWNTO 0); hour_time : IN STD_LOGIC_VECTOR(7 DOWNTO 0); minute_time : IN STD_LOGIC_VECTOR(7 DOWNTO 0); second_time : IN STD_LOGIC_VECTOR(7 DOWNTO 0); countdown_hour_time : IN STD_LOGIC_VECTOR(7 DOWNTO 0); countdown_minute_time : IN STD_LOGIC_VECTOR(7 DOWNTO 0); countdown_second_time : IN STD_LOGIC_VECTOR(7 DOWNTO 0); HEX5 : OUT STD_LOGIC_VECTOR(7 DOWNTO 0);--数码管段选 HEX4 : OUT STD_LOGIC_VECTOR(7 DOWNTO 0);--数码管段选 HEX3 : OUT STD_LOGIC_VECTOR(7 DOWNTO 0);--数码管段选 HEX2 : OUT STD_LOGIC_VECTOR(7 DOWNTO 0);--数码管段选 HEX1 : OUT STD_LOGIC_VECTOR(7 DOWNTO 0);--数码管段选 HEX0 : OUT STD_LOGIC_VECTOR(7 DOWNTO 0)--数码管段选 ); END COMPONENT; --设置模式 COMPONENT set_mode IS PORT ( clk_50M : IN STD_LOGIC; set_mode_key : IN STD_LOGIC; led_mode : OUT STD_LOGIC_VECTOR(3 DOWNTO 0); state_mode : OUT STD_LOGIC_VECTOR(3 DOWNTO 0) ); END COMPONENT; --倒计时模块 COMPONENT timing IS PORT ( clk_50M : IN STD_LOGIC; clk_1Hz : IN STD_LOGIC; state_mode : IN STD_LOGIC_VECTOR(3 DOWNTO 0); set_time_key : IN STD_LOGIC; confirm_key : IN STD_LOGIC; change_time_key : IN STD_LOGIC; countdown_hour_time : OUT STD_LOGIC_VECTOR(7 DOWNTO 0); countdown_minute_time : OUT STD_LOGIC_VECTOR(7 DOWNTO 0); countdown_second_time : OUT STD_LOGIC_VECTOR(7 DOWNTO 0) ); END COMPONENT; --秒表模块 COMPONENT stopwatch IS PORT ( clk_50M : IN STD_LOGIC; clk_100Hz : IN STD_LOGIC; state_mode : IN STD_LOGIC_VECTOR(3 DOWNTO 0); start_key : IN STD_LOGIC; stop_key : IN STD_LOGIC; reset_key : IN STD_LOGIC; stopwatch_Millisecond : OUT STD_LOGIC_VECTOR(7 DOWNTO 0); stopwatch_second : OUT STD_LOGIC_VECTOR(7 DOWNTO 0); stopwatch_minute : OUT STD_LOGIC_VECTOR(7 DOWNTO 0) ); END COMPONENT; --分频模块 COMPONENT fenping IS PORT ( clk_50M : IN STD_LOGIC; clk_1Hz : OUT STD_LOGIC; clk_100Hz : OUT STD_LOGIC ); END COMPONENT; --按键消抖 COMPONENT key_jitter IS PORT ( clkin : IN STD_LOGIC; key_in : IN STD_LOGIC; key_negedge : OUT STD_LOGIC ); END COMPONENT; --计时模块 COMPONENT jishi IS PORT ( clk_50M : IN STD_LOGIC; clk_1Hz : IN STD_LOGIC; state_mode : IN STD_LOGIC_VECTOR(3 DOWNTO 0); set_time_key : IN STD_LOGIC; confirm_key : IN STD_LOGIC; change_time_key : IN STD_LOGIC; hour_time : OUT STD_LOGIC_VECTOR(7 DOWNTO 0); minute_time : OUT STD_LOGIC_VECTOR(7 DOWNTO 0); second_time : OUT STD_LOGIC_VECTOR(7 DOWNTO 0) ); END COMPONENT; SIGNAL state_mode : STD_LOGIC_VECTOR(3 DOWNTO 0);--当前模式,4'd0:计时,4'd1:闹钟,4'd2:跑表 SIGNAL hour_time : STD_LOGIC_VECTOR(7 DOWNTO 0);--时 SIGNAL minute_time : STD_LOGIC_VECTOR(7 DOWNTO 0);--分 SIGNAL second_time : STD_LOGIC_VECTOR(7 DOWNTO 0);--秒 SIGNAL alarm_hour_time : STD_LOGIC_VECTOR(7 DOWNTO 0);--闹钟时 SIGNAL alarm_minute_time : STD_LOGIC_VECTOR(7 DOWNTO 0);--闹钟分 SIGNAL alarm_second_time : STD_LOGIC_VECTOR(7 DOWNTO 0);--闹钟秒 SIGNAL stopwatch_Millisecond : STD_LOGIC_VECTOR(7 DOWNTO 0);--10毫秒 SIGNAL stopwatch_second : STD_LOGIC_VECTOR(7 DOWNTO 0);--秒 SIGNAL stopwatch_minute : STD_LOGIC_VECTOR(7 DOWNTO 0);--分 SIGNAL countdown_hour_time : STD_LOGIC_VECTOR(7 DOWNTO 0);--时 SIGNAL countdown_minute_time : STD_LOGIC_VECTOR(7 DOWNTO 0);--分 SIGNAL countdown_second_time : STD_LOGIC_VECTOR(7 DOWNTO 0);--秒 SIGNAL key_0_negedge : STD_LOGIC;--按键下降沿 SIGNAL key_1_negedge : STD_LOGIC;--按键下降沿 SIGNAL key_2_negedge : STD_LOGIC;--按键下降沿 SIGNAL key_3_negedge : STD_LOGIC;--按键下降沿 SIGNAL clk_1Hz : STD_LOGIC;--1Hz SIGNAL clk_100Hz : STD_LOGIC;--100Hz BEGIN --分频模块 fenping_Hz : fenping PORT MAP ( clk_50M => clk_50M, clk_1Hz => clk_1Hz,--1Hz clk_100Hz => clk_100Hz--100Hz ); --按键消抖 key_0_jitter : key_jitter PORT MAP ( clkin => clk_50M, key_in => key_0, key_negedge => key_0_negedge ); --按键消抖 key_1_jitter : key_jitter PORT MAP ( clkin => clk_50M, key_in => key_1, key_negedge => key_1_negedge ); --按键消抖 key_2_jitter : key_jitter PORT MAP ( clkin => clk_50M, key_in => key_2, key_negedge => key_2_negedge ); --按键消抖 key_3_jitter : key_jitter PORT MAP ( clkin => clk_50M, key_in => key_3, key_negedge => key_3_negedge ); i_set_mode : set_mode PORT MAP ( clk_50M => clk_50M, set_mode_key => key_0_negedge, led_mode => led_mode,--led显示当前模式 state_mode => state_mode--当前模式,4'd0:计时,4'd1:闹钟,4'd2:跑表 ); i_jishi : jishi PORT MAP ( clk_50M => clk_50M, clk_1Hz => clk_1Hz, state_mode => state_mode,--当前模式,4'd0:计时,4'd1:闹钟,4'd2:跑表 set_time_key => key_1_negedge,--设置时间 confirm_key => key_2_negedge,--确认 change_time_key => key_3_negedge,--设置时分秒 hour_time => hour_time,--时 minute_time => minute_time,--分 second_time => second_time--秒 ); i_alarm_clock : alarm_clock PORT MAP ( clk_50M => clk_50M, state_mode => state_mode,--当前模式,4'd0:计时,4'd1:闹钟,4'd2:跑表 set_time_key => key_1_negedge,--设置时间 confirm_key => key_2_negedge,--确认 change_time_key => key_3_negedge,--设置时分秒 alarm_hour_time => alarm_hour_time,--时 alarm_minute_time => alarm_minute_time,--分 alarm_second_time => alarm_second_time--秒 ); i_stopwatch : stopwatch PORT MAP ( clk_50M => clk_50M, clk_100Hz => clk_100Hz,--100Hz--对应10ms i_timing : timing PORT MAP ( clk_50M => clk_50M, clk_1Hz => clk_1Hz, state_mode => state_mode,--当前模式,4'd0:计时,4'd1:闹钟,4'd2:跑表,4'd3:定时 set_time_key => key_1_negedge,--设置时间 confirm_key => key_2_negedge,--确认 change_time_key => key_3_negedge,--设置时分秒 countdown_hour_time => countdown_hour_time,--时 countdown_minute_time => countdown_minute_time,--分 countdown_second_time => countdown_second_time--秒 ); i_Bell : Bell PORT MAP ( clk_50M => clk_50M, clear_alarm => key_3_negedge,--关闭闹钟键(key3) alarm_hour_time => alarm_hour_time,--闹钟时 alarm_minute_time => alarm_minute_time,--闹钟分 alarm_second_time => alarm_second_time,--闹钟秒 hour_time => hour_time,--时 minute_time => minute_time,--分 second_time => second_time,--秒 countdown_hour_time => countdown_hour_time,--时 countdown_minute_time => countdown_minute_time,--分 countdown_second_time => countdown_second_time,--秒 bell_out => bell_out--蜂鸣器,蜂鸣器响 );
扫描文章末尾的公众号二维码
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。