digitalclock.vhd.txt

来自「实现电子钟的功能」· 文本 代码 · 共 217 行

TXT
217
字号
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;

entity digitalclock is
port(
     clk:in std_logic;   ---计时时钟脉冲输入
     bellclk:in std_logic;  ---闹铃/整点提示音脉冲输入
     mode:in std_logic;    ---正常走时和闹铃模式选择
     min:in std_logic;   ---分钟调整
     hour:in std_logic;  ---小时调整
     sl,sh:out std_logic_vector(3 downto 0);   ---秒高、低位
     ml,mh:out std_logic_vector(3 downto 0);   ---分高、低位
     hl,hh:out std_logic_vector(3 downto 0);   ---时高、低位
     speaker:out std_logic                        ---闹铃/整点提示音脉冲输出
     );
end;

architecture a of digitalclock is
signal temp_sl,temp_sh:std_logic_vector(3 downto 0);     ---正常走时秒高、低位
signal temp_ml,temp_mh:std_logic_vector(3 downto 0);     ---正常走时分高、低位
signal temp_hl,temp_hh:std_logic_vector(3 downto 0);     ---正常走时时高、低位
signal temp_bsl,temp_bsh:std_logic_vector(3 downto 0);    ---闹钟秒高、低位
signal temp_bml,temp_bmh:std_logic_vector(3 downto 0);    ---闹钟分高、低位
signal temp_bhl,temp_bhh:std_logic_vector(3 downto 0);    ---闹钟时高、低位

begin
--------------------------------------------------------------------------------------------
---------------------------------进程1功能:显示时间----------------------------------------
--------------------------------------------------------------------------------------------
process
begin
  if mode='0'   then           ---mode='0'显示正常走时              
         sl<=temp_sl;
         sh<=temp_sh;
         ml<=temp_ml;
         mh<=temp_mh;
         hl<=temp_hl;
         hh<=temp_hh;
   else                     ---mode='1'显示闹钟时间                
          sl<=temp_bsl;
         sh<=temp_bsh;
         ml<=temp_bml;
         mh<=temp_bmh;
         hl<=temp_bhl;
         hh<=temp_bhh;
end  if;
end process;
--------------------------------------------------------------------------------------------
------------------------------------进程1结束-----------------------------------------------
--------------------------------------------------------------------------------------------

--------------------------------------------------------------------------------------------
--------------------------------进程2功能:走时与校时,设置闹铃-----------------------------
--------------------------------------------------------------------------------------------
process(clk)                    
begin
if clk'event and clk='1' then 
             if temp_hh="0010" and temp_hl="0011"     ---正常走时
                and temp_mh="0101" and temp_ml="1001"
                and temp_sh="0101" and temp_sl="1001"
                then
                 temp_hh<="0000";
                 temp_hl<="0000";
                 temp_mh<="0000";
                 temp_ml<="0000";
                 temp_sh<="0000";
                 temp_sl<="0000";
             else    
                 if temp_hl="1001" 
                    and temp_mh="0101"and temp_ml="1001"
                    and temp_sh="0101" and temp_sl="1001"
                    then 
                    temp_hl<="0000";
                    temp_mh<="0000";
                    temp_ml<="0000";
                    temp_sh<="0000";
                    temp_sl<="0000";
                    temp_hh<=temp_hh+1;
                 else 
                     if temp_mh="0101" and temp_ml="1001"
                        and temp_sh="0101" and temp_sl="1001"
                        then
                        temp_mh<="0000"; 
                        temp_ml<="0000";               
                        temp_sh<="0000";
                        temp_sl<="0000";
                        temp_hl<=temp_hl+1;
                     else
                         if temp_ml="1001"
                            and temp_sh="0101" and temp_sl="1001"
                            then
                            temp_ml<="0000";               
                            temp_sh<="0000";
                            temp_sl<="0000";
                            temp_mh<=temp_mh+1;
                         else
                             if temp_sh="0101" and temp_sl="1001"
                                then
                                temp_sh<="0000";
                                temp_sl<="0000";
                                temp_ml<=temp_ml+1;
                             else
                                 if  temp_sl="1001"
                                     then
                                     temp_sl<="0000";
                                     temp_sh<=temp_sh+1;
                                 else
                                         temp_sl<=temp_sl+1;
                                 end if;
                             end if;
                        end if;
                    end if;
                end if;
            end if; 

       if mode='1'      then                  ---mode='1'显示闹钟时间
          if min='1'	then		      ---min='1'调整闹钟时间的分钟
	     if temp_bml="1001"   then
		if temp_bmh="0101"     then
		            temp_bmh<="0000";
		else
			    temp_bmh<=temp_bmh+1;
	        end if; 
 		temp_bml<="0000";
	     else
		temp_bml<=temp_bml+1;
	  end  if;
	  else
          if hour='1'	then                 ---hour='1'调整闹钟时间的小时
             if temp_bhh="0010"	then
		if	temp_bhl="0011"  then
		                temp_bhl<="0000";
			        temp_bhh<="0000";
	        else  
		          temp_bhl<=temp_bhl+1;
	        end if;
             else
                if temp_bhl="1001"  then
				temp_bhh<=temp_bhh+1;
				temp_bhl<="0000";
                else
	                  temp_bhl<=temp_bhl+1;
                end if;
             end if;
          else
              temp_bsl<=temp_bsl;
              temp_bsh<=temp_bsh;
              temp_bml<=temp_bml;
              temp_bmh<=temp_bmh;
              temp_bhl<=temp_bhl;
              temp_bhh<=temp_bhh;
          end if; 
         end if;
         else                             ---mode='0'显示正常走时的时间
		 if min='1'	then	  ---min='1'调整正常走时的分钟
		    if temp_ml="1001"  	then
			if temp_mh="0101"     then
				   	temp_mh<="0000";
		        else
			        temp_mh<=temp_mh+1;
	                end if; 
 			temp_ml<="0000";
		    else
				temp_ml<=temp_ml+1;
	            end  if;
	        else
                   if hour='1'	then                    ---hour='1'调整正常走时的时钟
		      if temp_hh="0010"	then
			 if	temp_hl="0011"  then
				    temp_hl<="0000";
			            temp_hh<="0000";
	                 else  
		                temp_hl<=temp_hl+1;
	                 end if;
                     else
                       if temp_hl="1001"  then
					temp_hh<=temp_hh+1;
					temp_hl<="0000";
                       else
	                       temp_hl<=temp_hl+1;
                       end if;
                     end if;
                  end if;
	        end if;
	end if; ---if mode='1'结束
end if;   ---if clk'event and clk='1'结束
   end process;
--------------------------------------------------------------------------------------------
------------------------------------进程2结束-----------------------------------------------
--------------------------------------------------------------------------------------------

--------------------------------------------------------------------------------------------
------------------------------------进程3功能:响铃-----------------------------------------
--------------------------------------------------------------------------------------------
process(bellclk)             
   begin
    if temp_sl="0000" and temp_sh="0000"           ---整点提示
            and temp_mh="0000" and temp_ml="0000"
				then
         speaker<=bellclk;
    else
      if   temp_ml=temp_bml  and temp_mh=temp_bmh    ---达到设定的闹铃时间,闹铃响
           and temp_hl=temp_bhl  and temp_hh=temp_bhh
         then
        speaker<=bellclk;
    end if;
   end if;
end process;
--------------------------------------------------------------------------------------------
------------------------------------进程3结束-----------------------------------------------
--------------------------------------------------------------------------------------------
end; 



⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?