⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 digtal.txt

📁 时、分、秒、实现数字钟的基本VHDL源代码。
💻 TXT
字号:
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;

entity digital_clock is port(
clk,iset,oset,en:in std_logic;
i1,i2,i3,i4:in std_logic_vector(3 downto 0);
o1,o2,o3,o4,o5,o6:out std_logic_vector(3 downto 0)
); 
end digital_clock;
architecture rtl of digital_clock is 

signal hmd:integer;
signal om:std_logic_vector(1 downto 0):="00";
signal zs:std_logic_vector(1 downto 0):="00";
signal ya,yb,yc,yd,moa,mob,da,db,ha,hb,ma, mb,sa,sb,ms:std_logic_vector(3 downto 0);
signal bya,byb,byc,byd,bmoa,bmob,bda,bdb,bha,bhb,bma, bmb,bsa,bsb,bms:std_logic_vector(3 downto 0);
---signal for computer week:
--signal year,y4,y100,y400,res,q7:std_logic_vector(11 downto 0);
--signal month,day,res1:integer;
 
--signal r4,m4,m7,week:std_logic_vector(2 downto 0);
--signal r100,m100:std_logic_vector(6 downto 0);
--signal r400,m400:std_logic_vector(8 downto 0);


begin 

in_set:process(iset) 	    --zs切换键
      begin
           if(iset='1' and iset'event) then 
		        zs<=zs+'1';
           end if;
end process in_set;

out_set:process(oset)	   --om切换键
begin
        if(oset='1' and oset'event) then 
	          om<=om+'1';
        end if;
end process out_set;

input:process(zs,iset)
begin
      if(iset='1' and iset'event) then 				--秒、0.1秒初始设置0
               bsa<="0000";bsb<="0000";bms<="0000"; 
		
		   if zs="00" then 
		          bya<=i1;byb<=i2;byc<=i3;byd<=i4;  --年份设定
             elsif zs="01" then 
		           bmoa<=i1;bmob<=i2;bda<=i3;bdb<=i4; 	  --月份、日期设定
		   elsif zs="10" then 
		           bha<=i1;bhb<=i2;bma<=i3;bmb<=i4; 	  --小时、分钟设定
		   else 
            end if;
      end if;
end process input;

output:process(om)
begin
     if om="01" then 
       o1<=ma;o2<=mb;o3<=sa;o4<=sb;o5<=ms;o6<="0000";   --分、秒、0.1秒
	elsif om="10" then 
	       o1<=moa;o2<=mob;o3<=da;o4<=db;o5<=ha;o6<=hb;   --月、日、时
     elsif om="11" then 
           o1<="0000"; o2<="0000";o3<=ya;o4<=yb;o5<=yc;o6<=yd;	   --年份
      else
	end if;
 
end process output;

a1:process(clk)
begin
if(clk='1' and clk'event) then 
         if en='0' then		 --置数使能
              ya<=bya;
		    yb<=byb;
		    yc<=byc;
		    yd<=byd;
		    
		    moa<=bmoa;
		    mob<=bmob;
			da<=bda;
			db<=bdb;
			ha<=bha;
			hb<=bhb; 
			ma<=bma;
			mb<=bmb;
			sa<=bsa;
			sb<=bsb;
			ms<=bms; 
		else 
                ms<=ms+'1'; 
                if ms="1001" then 
			           ms<="0000"; 
                          if sb/="1001" then 	    --秒计数
					            sb<=sb+'1'; 
                          else sb<="0000"; 
                                 if sa/="0101" then 
						            sa<=sa+'1'; 
                                 else sa<="0000"; 
                                        if mb/="1001" then 	   --分钟
								        mb<=mb+'1'; 
                                        else mb<="0000"; 
                                              if ma/="0101" then 
									           ma<=ma+'1'; 
									else 
                                                  ma<="0000"; 
                                                   if(hb/="1001") and ((hb/="0011") or (ha/="0010")) then  --小时非特殊情况个位加一 
										         hb<=hb+'1'; 
                                                   elsif hb="1001" then 			 --小时个位是9
		 hb<="0000"; ha<=ha+'1'; 
  elsif (hb="0011" and ha="0010") then 	 --小时23时下一步清零
	hb<="0000"; ha<="0000";
                                                           if(db/="1001")   and   ((conv_integer(da)*10+conv_integer(db))/=hmd)	
						 --一个月范围未溢出或月份个位不等于9则个位加一
 								                     
 then                                                            db<=db+'1'; 
											    elsif(conv_integer(da)*10+conv_integer(db))=hmd then 
										 --一个月份天数记到则日期归于下  da<="0000"; 
db<="0001"; 
													    if(mob/="1001")and((mob/="0010")or(moa/="0001"))then
													    --月份不等于9、12
                                                                              mob<=mob+'1'; 
                                                                     elsif mob="1001" then 
 														  --9月进位为10月
                                                                          mob<="0000";moa<="0001"; 
													    
 else mob<="0001";moa<="0000"; 
														            if(yd/="1001") then 		 --年份进位
                                                                                         yd<=yd+'1'; 
															       
else yd<="0000"; 
                                                                                           if(yc/="1001") then 
																		       yc<=yc+'1'; 
                                                                                           else yc<="0000"; 
                                                                                                    if(yb/="1001") then 
																				       yb<=yb+'1'; 
                                                                                                     else 
																				 yb<="0000"; 
																				 ya<=ya+'1'; 
																				 end if; 
                                                                                            end if; 
 end if;
end if; 
                                                         
    elsif db="1001" then  --如果日期个位为9则个位清零,十位加一
		 db<="0000"; da<=da+'1'; 
											
                                          end if; 
										end if; 
									end if; 
                            end if; 
					     end if; 
				    end if; 
                else end if; 
	  end if; 
  else 
  end if;
end process a1;


a2:process(moa,mob,ya,yb,yc,yd)
begin 
     if((mob="0000")and(moa="0001"))or(mob="0011")or(mob="0101") or(mob="0111")or(mob="1000")or(mob="0000")or(mob="0010" and moa="0001") then 
           hmd<=31;
		 --1、3、5、7、8、10、12月份有31天
      elsif mob="0010" then 			--2月
	       if(yc="0000")and(yd="0000")then
 
                   if(yb(0)='0')and (yb(1)=ya(0))then –偶400或奇800年为闰年
		            hmd<=29; 
                 else hmd<=28; -- 年份低两位为零并且不是偶400或奇800年
		            end if; 
              elsif (yd(0)='0')and(yd(1)='0')then --如果年份为四的倍数
	             hmd<=29; 
		    else 
		    hmd<=28;
              end if;
       else hmd<=30; --4、6、9、11月份为30天 
	  end if;
end process a2;

end rtl;

⌨️ 快捷键说明

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