vhdl具有闹钟功能的电子时钟设计


				--数字时钟

library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;

entity clock is
	port(	clk	:	in	std_logic;			-- 输入 1mhz 时钟
		   reset:	in 	std_logic;			--	时钟复位
			mod_set	:	in	std_logic_vector(1 downto 0);		--模式调节选择   00:显示时间     01:调节时钟			10: 闹钟
		minute_set  :	in	std_logic;							--分位调节
		   hout_set	:	in std_logic;							--时位调节
			cen	:	in 	std_logic;			--键入信号
			alarm_load	:	in std_logic;
		  segment:	out std_logic_vector(7 downto 0);			--段选信号
		  status:	out std_logic_vector(6 downto 0);
			  led: out std_logic_vector(23 downto 0));			--位选信号
	end clock;

	architecture bav of clock is

				--调用时钟计数模块声明						

component hour_l is
	port(	h_clear :  in     std_logic;
			h_load  :  in     std_logic; 
			h_clk :  in     std_logic;
		clock_hour:	 buffer  std_logic_vector(7 downto 0));
end component;

				--调用分频模块声明

component erzp is 
port(	clk_1mhz: in std_logic;
		clk_1hz: out std_logic;
		clk_5hz: out std_logic;
		clk_250hz: out std_logic);
end component;

				--调用分钟计数模块声明

component minute_l is
	port(		m_clear :  in     std_logic;
				m_load  :  in     std_logic;
				m_clk :  in     std_logic;
			set_hour  :	 in		std_logic;
		 minute_cout  :  out    std_logic;
		 clock_minute :	 buffer  std_logic_vector(7 downto 0));
end component;

				--调用秒钟计数模块声明

component second_1 is
	port(		s_en    :  in     std_logic;
				s_clear :  in     std_logic;
				s_load  :  in     std_logic;
				s_clk :  in     std_logic;
			set_minute:	 in		std_logic;
		 second_cout  :  out    std_logic;
		  clock_second:	 buffer  std_logic_vector(7 downto 0));
end component;

				--调用数码显示模块声明

component display is
	port(		scan_clk,rst	:	in std_logic;
			hour,minute,second	:	in std_logic_vector(7 downto 0);
							qh	:	out std_logic_vector(7 downto 0);
							y	:	out std_logic_vector(6 downto 0));
		
	end component;

				--调用时钟调节模块声明

component adjust is
	port(	en 	: 	in std_logic_vector(1 downto 0);
			add	: 	in std_logic;
			output_shi_h	:	out std_logic_vector(3 downto 0);
			output_shi_l	:	out std_logic_vector(3 downto 0);
			output_fen_h	:	out std_logic_vector(3 downto 0);
			output_fen_l	:	out std_logic_vector(3 downto 0);
			output_miao_h	:	out	std_logic_vector(3 downto 0);
			output_miao_l	:	out	std_logic_vector(3 downto 0));
end component;

					--调用闹钟模块声明

component alarm is
	port (	in_set   	: 	in std_logic;
			minute_in	:	in std_logic_vector(7 downto 0);
			hour_in		:	in std_logic_vector(7 downto 0);
			alarm_in_h	: 	in std_logic;
			alarm_in_m	:	in std_logic;
			out_set		:	out std_logic;
			alarm_load	:	in std_logic;
			minute_out	:	out std_logic_vector(7 downto 0);
			hour_out	:	out std_logic_vector(7 downto 0));
end component;

					--调用消抖模块声明

component key is
	port (	clk,kin :	in std_logic;
			kout	:	out std_logic);
end component;

					--调用模式选择模块声明

component sel is
	port ( 	md : in std_logic_vector(1 downto 0);
			in_h:in std_logic_vector(7 downto 0);
			in_m:in std_logic_vector(7 downto 0);
			in_s:in std_logic_vector(7 downto 0);
			alarm_h:in std_logic_vector(7 downto 0);
			alarm_m:in std_logic_vector(7 downto 0);
			pla_h:out std_logic_vector(7 downto 0);
			pla_m:out std_logic_vector(7 downto 0);
			pla_s:out std_logic_vector(7 downto 0);
			adjust_t:out std_logic;
			ala_t:out std_logic);
end component;

				--调用led流水灯模块声明

component led_l	is
	port (	in_set	: 	in std_logic;
			clk		:	in std_logic;
			led 	:	buffer std_logic_vector(23 downto 0));
end component;

signal c_co,m_co: std_logic;											--秒钟、时钟进位信号
signal in_hour,in_minute,in_second: std_logic_vector(7 downto 0);		       --秒、时、分数据信号
signal clock_1,clock_2,clock_3:	std_logic;			--计数时钟、扫描时钟
signal en_minute,en_hour: std_logic;
signal hour_dh, min_dh, sec_dh:std_logic_vector(7 downto 0);					--时间数据
signal load:std_logic;
signal ala_h,ala_m:std_logic_vector(7 downto 0);								--闹钟数据
signal x:std_logic;															--闹钟信号
signal y:std_logic;
begin

u0:	erzp		port map (	clk_1mhz=>clk,clk_1hz=>clock_1,clk_5hz=>clock_2,clk_250hz=>clock_3);

u1:	key			port map (	clk=>clock_2,kin=>minute_set,kout=>en_minute);

u2: key			port map (	clk=>clock_2,kin=>hout_set,kout=>en_hour);

u3: led_l 		port map (	in_set=>y,clk=>clock_3,led=>led);

u4: sel 		port map (	md=>mod_set,in_h=>hour_dh,in_m=>min_dh,in_s=>sec_dh,alarm_h=>ala_h,alarm_m=>ala_m,adjust_t=>load,
							pla_h=>in_hour,pla_m=>in_minute,pla_s=>in_second,ala_t=>x);


u5: alarm		port map (	minute_in=>min_dh,hour_in=>hour_dh,alarm_in_h=>en_hour,alarm_in_m=>en_minute,in_set=>x,
							out_set=>y,minute_out=>ala_m,hour_out=>ala_h,alarm_load=>alarm_load);
u6:	second_1	port map (	s_clk=>clock_1,s_clear=>reset,s_load=>load,s_en=>cen,second_cout=>c_co,set_minute=>en_minute,
							clock_second=>sec_dh);
u7:	minute_l	port map (	m_clk=>c_co,m_clear=>reset,m_load=>load,minute_cout=>m_co,set_hour=>en_hour,
							clock_minute=>min_dh);
u8: hour_l		port map (	h_clk=>m_co,h_clear=>reset,h_load=>load,clock_hour=>hour_dh);

u9: display		port map (	scan_clk=>clk,rst=>reset,qh=>segment,y=>status,hour=>in_hour,minute=>in_minute,
							second=>in_second);
end bav;

				--时钟计数模块

library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all; 

entity hour_l is
   port(	h_clear :  in     std_logic;
			h_load  :  in     std_logic; 
			h_clk   :  in     std_logic;
		clock_hour:	 buffer  std_logic_vector(7 downto 0));
end hour_l;
architecture behave of hour_l is
begin   
    process (h_clk)
		variable tmpl,tmph :std_logic_vector(3 downto 0);
		begin
			if(h_clear='0') then				--异步清零
				tmpl:="0000";
				tmph:="0000";    
			else
				if(h_clk'event and h_clk='1')then
					if (tmpl="1001" or (tmph="0010"and tmpl="0011")) then
						tmpl:="0000";                  
						if(tmph="0010" ) then
							tmph:="0000";						
						else                   
							tmph:=tmph+1;
						end if;
					else
						tmpl:=tmpl+1; 
					end if;
				end if;
			end if;                                   
			clock_hour(3 downto 0) <= tmpl(3 downto 0);
			clock_hour(7 downto 4) <= tmph(3 downto 0);
	end  process;
end  behave;

				--分钟计数模块
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;

entity minute_l is
   port(		m_clear : 	 in     std_logic;							--清零
				m_load  : 	 in     std_logic;							--时间调节信号
				m_clk   : 	 in     std_logic;							--时钟信号
			   set_hour	:	 in		std_logic;							--调节时位
		  minute_cout  	: 	 out    std_logic;						--进位
		  clock_minute 	:	buffer  std_logic_vector(7 downto 0));			--输出信号
end minute_l;
architecture bhv of minute_l is
signal co :std_logic;
begin
	process (m_clk)
		variable tmpl,tmph :std_logic_vector(3 downto 0);
		begin
			if (m_clear='0') then
				tmpl:="0000";
				tmph:="0000";
			else
				if(m_clk'event and m_clk='1')then	
					if(tmpl="1001")then
						tmpl:="0000";
						if(tmph="0101")then
							tmph:="0000";
						else
							tmph:=tmph+1;
						end if;
					else
						tmpl:=tmpl+1;
					end if;
				end if;
			end if;
		clock_minute(3 downto 0)<=tmpl;
		clock_minute(7 downto 4)<=tmph;
	end process;
	
process
begin
	wait until (m_clk='1');
		if(clock_minute="01011001")then
			co<='1';
		else 
			co<='0';
		end if;
		
end process;

process(m_load)
begin
	if(m_load='1')then
		minute_cout <= co or (not set_hour);
	else
		minute_cout <= co;
	end if;
end process;
end bhv;

				--秒钟计数模块

library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;

entity second_1 is
   port(		s_en    :  in     std_logic;
				s_clear :  in     std_logic;
				s_load  :  in     std_logic;
				set_minute	:  in	  std_logic;
				s_clk   :  in     std_logic;
		 second_cout  :  out    std_logic;
		  clock_second:	 buffer  std_logic_vector(7 downto 0));
end second_1;
architecture bhv of second_1 is
signal co : std_logic;
begin
	process (s_clk)
		variable tmpl,tmph :std_logic_vector(3 downto 0);
		begin
			if (s_clear='0') then
				tmpl:="0000";
				tmph:="0000";
			else
				if(s_clk'event and s_clk='1')then
					if(s_en='1')then
						if(tmpl="1001")then
							tmpl:="0000";
							if(tmph="0101")then
								tmph:="0000";
							else
								tmph:=tmph+1;
							end if;
						else
							tmpl:=tmpl+1;
						end if;
					end if;
				end if;
			end if;
		clock_second(3 downto 0)<=tmpl;
		clock_second(7 downto 4)<=tmph;
	end process;

process 
begin
	wait until(s_clk='1');
		if(clock_second="01011001")then
			co<='1';
		else 
			co<='0';
		end if;	
end process;

process(s_load)
begin
	if(s_load='1')then
		second_cout <= co or (not set_minute);
	else
		second_cout <= co;
	end if;
end process;
end bhv;

							--闹钟模块

library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all; 
entity alarm is
	port (	in_set   	: 	in std_logic;										--闹钟控制信号
			minute_in	:	in std_logic_vector(7 downto 0);					--时间信息的输入
			hour_in		:	in std_logic_vector(7 downto 0);
			alarm_in_h	: 	in std_logic;										--设定闹钟时间
			alarm_in_m	:	in std_logic;
			out_set		:	out std_logic;											--输出LED闪烁信号
			alarm_load	:	in std_logic;										--闹钟开关信号
			minute_out	:	out std_logic_vector(7 downto 0);					--显示设定时间
			hour_out	:	out std_logic_vector(7 downto 0));		
end entity;

architecture bhv of alarm is
		
begin 
	process(alarm_in_h,alarm_in_m)
		variable tmpl_m,tmph_m:std_logic_vector(3 downto 0);
		variable tmpl_h,tmph_h:std_logic_vector(3 downto 0);
		begin
		if(in_set='1')then
			if(alarm_in_m'event and alarm_in_m='1')then
				if(tmpl_m="1001")then
					tmpl_m:="0000";
					if(tmph_m="0101")then
						tmph_m:="0000";
					else
						tmph_m:=tmph_m+1;
					end if;
				else
					tmpl_m:=tmpl_m+1;
				end if;
			end if;
		
		if(alarm_in_h'event and alarm_in_h='1')then
			if (tmpl_h="1001" or (tmph_h="0010"and tmpl_h="0011"))then
				tmpl_h:="0000";                  
				if(tmph_h="0010" ) then
					tmph_h:="0000";						
				else                   
					tmph_h:=tmph_h+1;
				end if;
			else
				tmpl_h:=tmpl_h+1; 
			end if;
		end if;
	
		hour_out<=tmph_h & tmpl_h;
		minute_out<=tmph_m & tmpl_m;

	end if;	
	if(alarm_load='1')then
		if((hour_in= tmph_h &tmpl_h)and (minute_in=tmph_m & tmpl_m)) then 
				out_set<='1';
			else 
				out_set<='0';
		end if;
	else
		out_set<='0';
	end if;
end process;
end bhv;

					--数码显示模块
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;

entity display is
	port(		scan_clk,rst	:		in std_logic;
			hour,minute,second	:		in std_logic_vector(7 downto 0);						--输入时间信息
							qh	:		out std_logic_vector(7 downto 0);						--	位选信号
							y	:		out std_logic_vector(6 downto 0));						--段选信号
			
end display;

architecture bhv of display is
	signal date: std_logic_vector(3 downto 0);
	signal place:std_logic_vector(2 downto 0);

begin
	process(scan_clk,rst)
		variable q:std_logic_vector(2 downto 0);
		begin
			if rst='0' then q:=(others=>'0');
			elsif scan_clk'event and scan_clk='1' then
				if(q<7) then
					q:=q+1;
				else
					q:=(others=>'0');
				end if;
			end if;
		case q is
			when "000" =>date<=second(3 downto 0);
			when "001" =>date<=second(7 downto 4);
			when "010" =>date<=minute(3 downto 0);
			when "011" =>date<=minute(7 downto 4);
			when "100" =>date<=hour(3 downto 0);
			when "101" =>date<=hour(7 downto 4);
			when others =>date<="1010";
		end case;
		place<=q;
	end process;
	

process(place)
	begin
		case date is
			when "0000"=>y<="1111110";
			when "0001"=>y<="0110000";
			when "0010"=>y<="1101101";
			when "0011"=>y<="1111001";
			when "0100"=>y<="0110011";
			when "0101"=>y<="1011011";						--显示译码
			when "0110"=>y<="1011111";
			when "0111"=>y<="1110000";
			when "1000"=>y<="1111111";
			when "1001"=>y<="1111011";
			when "1010"=>y<="0000001";
			when others=>null;
		end case;
end process;
with place select
	   qh<= "11111110" when "000",
			"11111101" when "001",
			"11111011" when "010",
			"11110111" when "011",									--3-8译码
			"11101111" when "100",
			"11011111" when "101",
			"10111111" when "110",
			"01111111" when "111",
			"11111111" when others;
end bhv;

				--分频模块

library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;
 
entity erzp is 
	port(	clk_1mhz: in std_logic;
			clk_1hz: out std_logic;
			clk_5hz: out std_logic;
			clk_250hz: out std_logic);
end erzp;

architecture one of erzp is 
begin
	process(clk_1mhz)
		variable q1: integer range 0 to 100000;
		variable q2: integer range 0 to 200000;
		variable q3: integer range 0 to 4000;
		begin 
			if (clk_1mhz'event and clk_1mhz='1')then
-------------------1hz--------------------------
				if q1=99999 then 
					q1:=0;
				else 
					q1:=q1+1;
				end if;
				if q1<=49999 then 
					clk_1hz<='1';
				else 
					clk_1hz<='0';
				end if;

-------------------5hz--------------------------
				if q2=99 then 
					q2:=0;
				else 
					q2:=q2+1;
				end if;
				if q2<=49 then 
					clk_5hz<='1';
				else 
					clk_5hz<='0';
				end if;
-------------------250hz--------------------------
				if q3=1200 then 
					q3:=0;
				else 
					q3:=q3+1;
				end if;
				if q3<=600 then 
					clk_250hz<='1';
				else 
					clk_250hz<='0';
				end if;
			end if;
	end process ;
end one ;

				--led流水灯显示模块

library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all; 
entity led_l	is
	port (	in_set	: 	in std_logic;
			clk		:	in std_logic;
			led 	:	buffer std_logic_vector(23 downto 0));
end entity;

architecture bhv of led_l is
signal sel:std_logic_vector(4 downto 0);									--位选信号					--位
signal xel:std_logic;							
begin 
	process(clk) 
	variable a :std_logic_vector(4 downto 0);
	begin
		if(in_set='1')then
			if(clk'event and clk='1')then
				if(a<23)then												--位选计数
					a:=a+1;
				else
					a:=(others=>'0');
					
			end if;
		end if;
		sel<=a;
	else
		sel<="11000";
	end if;
end process;

process(clk)
variable q :integer range 0 to 2000;
variable a :std_logic;
variable q1:integer range 0 to 20;
begin
	if(clk'event and clk='1')then
		q:=q+1;
		if q<499 then
			case sel is 
				when "00000"=>led<="000000000000000000000001";
				when "00001"=>led<="000000000000000000000010";
				when "00010"=>led<="000000000000000000000100";
				when "00011"=>led<="000000000000000000001000";
				when "00100"=>led<="000000000000000000010000";
				when "00101"=>led<="000000000000000000100000";
				when "00110"=>led<="000000000000000001000000";
				when "00111"=>led<="000000000000000010000000";
				when "01000"=>led<="000000000000000100000000";
				when "01001"=>led<="000000000000001000000000";
				when "01010"=>led<="000000000000010000000000";
				when "01011"=>led<="000000000000100000000000";
				when "01100"=>led<="000000000001000000000000";
				when "01101"=>led<="000000000010000000000000";
				when "01110"=>led<="000000000100000000000000";
				when "01111"=>led<="000000001000000000000000";
				when "10000"=>led<="000000010000000000000000";
				when "10001"=>led<="000000100000000000000000";
				when "10010"=>led<="000001000000000000000000";
				when "10011"=>led<="000010000000000000000000";
				when "10100"=>led<="000100000000000000000000";
				when "10101"=>led<="001000000000000000000000";
				when "10110"=>led<="010000000000000000000000";
				when "10111"=>led<="100000000000000000000000";
				when others =>led<=	"000000000000000000000000";
			end case;
		elsif((q>500)and(q<999))then
			case sel is 
				when "00000"=>led<="100000000000000000000001";
				when "00001"=>led<="010000000000000000000010";
				when "00010"=>led<="001000000000000000000100";
				when "00011"=>led<="000100000000000000001000";
				when "00100"=>led<="000010000000000000010000";
				when "00101"=>led<="000001000000000000100000";
				when "00110"=>led<="000000100000000001000000";
				when "00111"=>led<="000000010000000010000000";
				when "01000"=>led<="000000001000000100000000";
				when "01001"=>led<="000000000100001000000000";
				when "01010"=>led<="000000000010010000000000";
				when "01011"=>led<="000000000001100000000000";
				when "01100"=>led<="000000000001100000000000";
				when "01101"=>led<="000000000010010000000000";
				when "01110"=>led<="000000000100001000000000";
				when "01111"=>led<="000000001000000100000000";
				when "10000"=>led<="000000010000000010000000";
				when "10001"=>led<="000000100000000001000000";
				when "10010"=>led<="000001000000000000100000";
				when "10011"=>led<="000010000000000000010000";
				when "10100"=>led<="000100000000000000001000";
				when "10101"=>led<="001000000000000000000100";
				when "10110"=>led<="010000000000000000000010";
				when "10111"=>led<="100000000000000000000001";
				when others =>led<=	"000000000000000000000000";
			end case;
		elsif((q>1000)and(q<1499))then
			case sel is 
				when "00000"=>led<="100000000000000000000000";
				when "00001"=>led<="010000000000000000000000";
				when "00010"=>led<="001000000000000000000000";
				when "00011"=>led<="000100000000000000000000";
				when "00100"=>led<="000010000000000000000000";
				when "00101"=>led<="000001000000000000000000";
				when "00110"=>led<="000000100000000000000000";
				when "00111"=>led<="000000010000000000000000";
				when "01000"=>led<="000000001000000000000000";
				when "01001"=>led<="000000000100000000000000";
				when "01010"=>led<="000000000010000000000000";
				when "01011"=>led<="000000000001000000000000";
				when "01100"=>led<="000000000000100000000000";
				when "01101"=>led<="000000000000010000000000";
				when "01110"=>led<="000000000000001000000000";
				when "01111"=>led<="000000000000000100000000";
				when "10000"=>led<="000000000000000010000000";
				when "10001"=>led<="000000000000000001000000";
				when "10010"=>led<="000000000000000000100000";
				when "10011"=>led<="000000000000000000010000";
				when "10100"=>led<="000000000000000000001000";
				when "10101"=>led<="000000000000000000000100";
				when "10110"=>led<="000000000000000000000010";
				when "10111"=>led<="000000000000000000000001";
				when others =>led<=	"000000000000000000000000";
			end case;
		else
			if(sel="11000")then
				led<=	"000000000000000000000000";
			else
				if(clk'event and clk='1')then
					if q1=40 then 
						q1:=0;
					else 
						q1:=q1+1;
					end if;
				
					if q1<=20 then 
						a:='1';
					else 
						a:='0';
					end if;
					
					if(a='1')then
						led<="111111111111111111111111";
					else 
						led<="000000000000000000000000";
				end if;
			end if;
		end if;
	end if;
	end if;
end process;
end bhv;

					--消抖模块

library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;

entity key is
port(clk,kin:in std_logic;           --按键按下时为0
		kout:out std_logic:='0');
end entity;

architecture behav of key is
begin

process(clk,kin) 
  variable count1 :integer range 0 to 100; 
begin 
	if kin='0' then 
		if rising_edge(clk) then
			if count1<100 then 
				count1:=count1+1; 
			else 
				count1:=count1;
			end if; 
			if count1<=99 then 
				kout<='1'; 
			else 
				kout<='0'; 
			end if; 
		end if; 
	else 
		count1:=0;
		kout<='1';
	end if; 
end process ;
end behav;

				--选择模块


library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;

entity sel is
	port ( 	md : in std_logic_vector(1 downto 0);									--模式选择信号
			in_h:in std_logic_vector(7 downto 0);									--时间信息
			in_m:in std_logic_vector(7 downto 0);
			in_s:in std_logic_vector(7 downto 0);
			alarm_h:in std_logic_vector(7 downto 0);								--设定的闹钟信息
			alarm_m:in std_logic_vector(7 downto 0);
			pla_h:out std_logic_vector(7 downto 0);
			pla_m:out std_logic_vector(7 downto 0);										--显示时间
			pla_s:out std_logic_vector(7 downto 0);
			adjust_t:out std_logic;														--时间调节信号
			ala_t:out std_logic);														--闹钟调节信号
end entity;

architecture bhv of sel is
begin 
	process(md)
	begin
		if(md="00")then
			pla_h<=in_h;
			pla_m<=in_m;													--若为"00"则显示时间
			pla_s<=in_s;
			adjust_t<='0';
			ala_t<='0';
		elsif(md="01")then
			pla_h<=in_h;												--若为"01"则显示时间且可调节时间
			pla_m<=in_m;
			pla_s<=in_s;
			adjust_t<='1';
			ala_t<='0';
		else
			pla_h<=alarm_h;
			pla_m<=alarm_m;														--若为其他则显示闹钟且可调节闹钟
			pla_s<="00000000";
			adjust_t<='0';
			ala_t<='1';
		end if;
	end process;
end bhv;
  • 11
    点赞
  • 73
    收藏
    觉得还不错? 一键收藏
  • 4
    评论
数字钟的设计 一、系统功能概述 (一)、系统实现的功能: 1、具有"时"、"分"、"秒"的十进制数字显示(小时从00 ~ 23)。 2、具有手动校时、校分、校秒的功能。 3、有定时和闹钟功能,能够在设定的时间发出闹铃声。 4、能进行整点报时。从59分50秒起,每隔2秒发一次低音"嘟"的信号,连续5次,最 后一次为高音"嘀"的信号。 (二)、各项设计指标: 1、显示部分采用的6个LED显示器,从高位至低位分别显示时、分、秒。 2、有一个设置闹钟定时时间、正常时间的按钮,选择调的对象。 3、有三个按钮分别调时、分、秒的时间。 4、有一个按钮用作开启/关闭闹铃。 5、另外需要两个时钟信号来给系统提供脉冲信号,使时钟闹钟正常工作,分别为 1Hz、1kHz的脉冲。 二、系统组成以及系统各部分的设计 1、系统结构描述 //要求:系统(或顶层文件)结构描述,各个模块(或子程序)的功能描述; 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的输入信号加一。在设置定时模式上,k ey上的脉冲只修改定时值,不影响时间脉冲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。 2. 系统各个模块的VHDL程序: (1)、CNT60_A_SEC模块: 程序源代码如下: library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity cnt60_a_sec is port( clk,clr,enb: in std_logic;-- 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; --进位输出,触发分计
功能数字时钟是一种集计时、计数、闹铃、温湿度显示等多种功能于一体的电子时钟。它广泛应用于生活、工作、教育等领域,成为现代社会不可缺少的一部分。要设计一个多功能数字时钟,需要用到VHDL语言。 首先,VHDL是一种硬件描述语言,它可以描述数字电路的行为和结构,也可以模拟数字电路的实现。我们可以利用VHDL语言实现数字时钟中的各种功能,如时钟、闹铃、温湿度显示等。 其次,设计功能数字时钟需要有几个关键模块。例如,时钟模块,它包括时钟的频率、时钟信号的分频、小时、分钟、秒的计数和显示等功能。还有,闹铃模块,它可以设置闹铃的时间和铃声,当时钟时间到达设定的闹铃时间时,闹铃即响。最后,温湿度显示模块,可以通过VHDL语言控制温湿度传感器的采集和数据显示等。 此外,采用VHDL进行数字时钟设计,有利于提高设计效率、简化开发流程和减少实现成本。因为VHDL语言可以模拟电路的实现过程,能够快速地检查和排除电路中的错误。同时,VHDL语言的可读性和可扩展性也为数字时钟设计和维护带来诸多便利。 综上所述,设计一个多功能数字时钟,需要用到VHDL语言,并开发出几个核心模块,而这些模块通过软件的方式进行实现,不仅能够提高效率,还能够保证数字时钟的可靠性和稳定性。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值