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

📄 数字钟.txt

📁 关于数字钟的实现
💻 TXT
字号:
library ieee;



use ieee.std_logic_1164.all;



use ieee.std_logic_unsigned.all;



entity szz is



port(clk:in std_logic;



        clk1:in std_logic;



        md1:in std_logic;



        md2:in std_logic_vector(1 downto 0);



        speak:out std_logic;



        dout:out std_logic_vector(6 downto 0);



        selout:out std_logic_vector(2 downto 0));



end szz;



architecture one of szz is



signal sel:std_logic_vector(2 downto 0);




signal hou1:std_logic_vector(3 downto 0);



signal hou2:std_logic_vector(3 downto 0);



signal min1:std_logic_vector(3 downto 0);



signal min2:std_logic_vector(3 downto 0);




signal seth1:std_logic_vector(3 downto 0);



signal seth2:std_logic_vector(3 downto 0);



signal setm1:std_logic_vector(3 downto 0);



signal setm2:std_logic_vector(3 downto 0);




signal sec1:std_logic_vector(3 downto 0);



signal sec2:std_logic_vector(3 downto 0);



signal h1:std_logic_vector(3 downto 0);



signal h2:std_logic_vector(3 downto 0);



signal m1:std_logic_vector(3 downto 0);



signal m2:std_logic_vector(3 downto 0);



signal s1:std_logic_vector(3 downto 0);



signal s2:std_logic_vector(3 downto 0);



-------------------------------------------------



begin



----------------------------------------------模6计数



choice:process(clk1)



begin



if clk1'event and clk1='1' then



if sel="101" then



sel<="000";



else



sel<=sel+1;



end if;



end if;



end process choice;



-----------------------------------------------小时十位



h110:process(clk,hou2,min1,min2,sec1,sec2,md1,md2)



begin



if clk'event and clk='1' then



if (hou1="0010" and hou2="0011")and(min1="0101" and min2="1001") and (sec1="0101" and sec2="1001")      then



hou1<="0000";



elsif hou1="0010"and hou2="0011"and md1='0' and md2="01" then--当时间为23点且处于校时状态时



hou1<="0000";



elsif (hou2="1001"and(min1="0101" and min2="1001") and (sec1="0101" and sec2="1001"))or (hou2="1001"and md1='0' and md2="01")     then




hou1<=hou1+1;



end if;



end if;



end process h110;



-----------------------------------------------小时个位



h220:process(clk,min1,min2,sec1,sec2,md1,md2,hou1)



begin



if clk'event and clk='1' then



if (hou1="0010" and hou2="0011")and(min1="0101" and min2="1001") and (sec1="0101" and sec2="1001") then



hou2<="0000";



elsif hou2="1001"and(min1="0101" and min2="1001") and (sec1="0101" and sec2="1001")     then



hou2<="0000";



elsif (hou2="1001"and md1='0' and md2="01")or (hou1="0010"and hou2="0011") then



hou2<="0000";--md<='1';



elsif ((min1="0101" and min2="1001") and (sec1="0101" and sec2="1001"))or (md1='0' and md2="01") then



hou2<=hou2+1;--speak<=clk;



end if;



end if;



end process h220;



-----------------------------------------------分钟十位



m110:process(clk,min2,sec1,sec2,md1,md2)



begin



if clk'event and clk='1' then



if (min1="0101" and min2="1001") and (sec1="0101" and sec2="1001") then 



min1<="0000";



elsif min1="0101"and min2="1001"and (md1='0' and md2="00")then



min1<="0000";




elsif (min2="1001"and (sec1="0101" and sec2="1001")) or (min2="1001"and md1='0' and md2="00")then



min1<=min1+1;



end if;



end if;--end if;



end process m110;



----------------------------------------------分钟个位



m220:process(clk,sec1,sec2,md1,md2)



begin



if clk'event and clk='1' then



if min2="1001"and (sec1="0101" and sec2="1001")then



min2<="0000";



elsif min2="1001"and (md1='0' and md2="00")then



min2<="0000";



else     if (sec1="0101" and sec2="1001") or(md1='0' and md2="00")then



min2<=min2+1;



end if;



end if;end if;



end process m220;



---------------------------------------------秒十位



s110:process(clk)



begin



if clk'event and clk='1' then



if (sec1="0101" and sec2="1001")then



sec1<="0000";



else if sec2="1001"then



sec1<=sec1+1;



end if;



end if;end if;



end process s110;



--------------------------------------------秒个位



s220:process(clk)



begin



if clk'event and clk='1' then



if sec2="1001" then



sec2<="0000";



else sec2<=sec2+1;



end if;



end if;



end process s220;



-------------------------------------------时间设置小时部分



sethour1:process(clk,seth2)



begin



if clk'event and clk='1' then



if seth1="0010"and seth2="0011" then



seth1<="0000";



elsif seth2="1001"     then



seth1<=seth1+1;



end if;



end if;



end process sethour1;



-------------------------------------------



sethour2:process(clk,md1,md2,seth1)



begin



if clk'event and clk='1' then



if (seth1="0010"and seth2="0011")or seth2="1001"then



seth2<="0000";



elsif md1='1' and md2="00" then



seth2<=seth2+1;



end if;



end if;



end process sethour2;



-------------------------------------------时间设置分钟部分



setmin1:process(clk,setm2)



begin



if clk'event and clk='1' then



if setm1="0101"and setm2="1001"then



setm1<="0000";



elsif setm2="1001"then



setm1<=setm1+1;



end if;



end if;



end process setmin1;



----------------------------------------------



setmin2:process(clk,md1,md2)



begin



if clk'event and clk='1'then



if setm2="1001"then



setm2<="0000";



elsif md1='1' and md2="01"then



setm2<=setm2+1;



end if;



end if;



end process setmin2;



--------------------------------------------



--------------------------------------------闹铃



speaker:process(clk1,hou1,hou2,min1,min2)



begin



if clk1'event and clk1='1'then



if seth1=hou1 and seth2=hou2 and setm1=min1 and setm2=min2 then



speak<=clk1;



else speak<='0';



end if;



end if;



end process speaker;



-------------------------------------------



-------------------------------------------



disp:process(sel,md1,hou1,hou2,min1,min2,sec1,sec2,seth1,seth2,setm1,setm2)



begin




if sel="000" then



selout<="000";



case h1 is



when "0000"=>dout<="0111111";



when "0001"=>dout<="0000110";



when "0010"=>dout<="1011011";



when others =>dout<="1000000";



end case;



elsif sel="001" then



selout<="001";



case h2 is



when "0000"=>dout<="0111111";



when "0001"=>dout<="0000110";



when "0010"=>dout<="1011011";



when "0011"=>dout<="1001111";



when "0100"=>dout<="1100110";



when "0101"=>dout<="1101101";



when "0110"=>dout<="1111101";



when "0111"=>dout<="0000111";



when "1000"=>dout<="1111111";



when "1001"=>dout<="1101111";



when others=>dout<="1000000";



end case;



elsif sel="010" then



selout<="010";



case m1 is



when "0000"=>dout<="0111111";



when "0001"=>dout<="0000110";



when "0010"=>dout<="1011011";



when "0011"=>dout<="1001111";



when "0100"=>dout<="1100110";



when "0101"=>dout<="1101101";



when others=>dout<="1000000";



end case;



elsif sel="011" then



selout<="011";



case m2 is



when "0000"=>dout<="0111111";



when "0001"=>dout<="0000110";



when "0010"=>dout<="1011011";



when "0011"=>dout<="1001111";



when "0100"=>dout<="1100110";



when "0101"=>dout<="1101101";



when "0110"=>dout<="1111101";



when "0111"=>dout<="0000111";



when "1000"=>dout<="1111111";



when "1001"=>dout<="1101111";



when others=>dout<="1000000";



end case;



elsif sel="100" then



selout<="100";



case s1 is



[hider] 



when "0000"=>dout<="0111111";



when "0001"=>dout<="0000110";



when "0010"=>dout<="1011011";



when "0011"=>dout<="1001111";



when "0100"=>dout<="1100110";



when "0101"=>dout<="1101101";



when others=>dout<="1000000";



end case;



elsif sel="101" then



selout<="101";



case s2 is



when "0000"=>dout<="0111111";



when "0001"=>dout<="0000110";



when "0010"=>dout<="1011011";



[/hider]when "0011"=>dout<="1001111";



when "0100"=>dout<="1100110";



when "0101"=>dout<="1101101";



when "0110"=>dout<="1111101";



when "0111"=>dout<="0000111";



when "1000"=>dout<="1111111";



when "1001"=>dout<="1101111";



when others=>dout<="1000000";



end case;



end if;



if md1='0'     then---------------计时时间显示和设置模式



h1<=hou1;h2<=hou2;



m1<=min1;m2<=min2;



s1<=sec1;s2<=sec2;



else                 -----------闹铃时间现实和设置模式



h1<=seth1;h2<=seth2;



m1<=setm1;m2<=setm2;



s1<="1111";s2<="1111";




end if;



end process disp;



------------------------------------------



end     one;





不用闹钟

Library ieee;
Use ieee.std_logic_1164.all;
Use ieee.std_logic_arith.all; 
Use ieee.std_logic_unsigned.all;
Entity watch is
Port(sel: out std_logic_vector(6 downto 1) ;
seg:out std_logic_vector(7 downto 0);
Beginstop:in std_logic;
Reset:in std_logic;
Cp2:in std_logic);
End watch;
Architecture behave of watch is
Signal num1: std_logic_vector(3 downto 0);
Signal num2: std_logic_vector(3 downto 0);
Signal num3: std_logic_vector(3 downto 0);
Signal num4: std_logic_vector(3 downto 0);
Signal num5: std_logic_vector(3 downto 0);
Signal num6: std_logic_vector(3 downto 0);
Signal num: std_logic_vector(3 downto 0);
Signal numlet: std_logic_vector(2 downto 0);
Signal count: std_logic_vector(17 downto 1);
Signal selsig: std_logic_vector(6 downto 1);
Signal segsig: std_logic_vector(7 downto 0 );
Signal cp1: std_logic;
Signal cp3: std_logic;
Begin
Process(cp2)  ----  分频。
  Begin 
    If (cp2' event and cp2='1') then 
      if (Count="1100011010011111")then
          count<="00000000000000000"; cp1<=not cp1;
         else count<=count+1;
          end if;
         end if;
         cp3<=count(10);
end process;
process(cp1)
   begin 
  if reset ='1' then num1(3 downto 0) <="0000";
                num2(3 downto 0) <="0000";
                num3(3 downto 0) <="0000";
                num4(3 downto 0) <="0000";
                num5(3 downto 0) <="0000";
                num6(3 downto 0) <="0000";
  
else if cp1' event and cp1='1' then 
if beginstop='1' then num1<=num1+1;
if num1 (3 downto 0)="1001" then 
  num1 (3 downto 0)<="0000"; num2<= num2+1;
if num2 (3 downto 0)="1001" then 
  num2 (3 downto 0)<="0000"; num3<= num3+1;
if num3 (3 downto 0)="1001" then 
  num3 (3 downto 0)<="0000"; num4<= num4+1;
if num4 (3 downto 0)="0101" then 
  num4 (3 downto 0)<="0000"; num5<= num5+1;
if num5 (3 downto 0)="1001" then 
  num5 (3 downto 0)<="0000"; num6<= num6+1;
if num6 (3 downto 0)="0101" then 
  num6(3 downto 0)<="0000";
end if; end if; end if; end if; end if; end if; end if;
end if; end if;
end process;
process (cp3) 
   begin 
if (cp3' event and cp3='1')then 
   if(numlet(2 downto 0)="000") then
   num<=num1;selsig(6 downto 1)<="111110"; end if;
if(numlet(2 downto 0)="001") then
   num<=num2;selsig(6 downto 1)<="111101"; end if;
if(numlet(2 downto 0)="010") then
   num<=num3;selsig(6 downto 1)<="111011"; end if;
if(numlet(2 downto 0)="011") then
   num<=num4;selsig(6 downto 1)<="110111"; end if;
if(numlet(2 downto 0)="100") then
   num<=num5;selsig(6 downto 1)<="101111"; end if;
   numlet(2 downto 0)<=numlet(2 downto 0)+1;
if(numlet(2 downto 0)="101") then
   numlet(2 downto 0)<="011111"; end if;
end if;
if (num (3 downto 0)="0000")then 
   segsig(7 downto 0)<="01111111"; end if;
if (num (3 downto 0)="0001")then 
   segsig(7 downto 0)<="00001101"; end if;
if (num (3 downto 0)="0010")then 
   segsig(7 downto 0)<="10110111"; end if;
if (num (3 downto 0)="0011")then 
   segsig(7 downto 0)<="10011111"; end if;
if (num (3 downto 0)="0100")then 
   segsig(7 downto 0)<="11001101"; end if;
if (num (3 downto 0)="0101")then 
   segsig(7 downto 0)<="11011011"; end if;
if (num (3 downto 0)="0110")then 
   segsig(7 downto 0)<="11111011"; end if;
if (num (3 downto 0)="0111")then 
   segsig(7 downto 0)<="00001111"; end if;
if (num (3 downto 0)="1000")then 
   segsig(7 downto 0)<="11111111"; end if;
if (num (3 downto 0)="1001")then 
   segsig(7 downto 0)<="11011111"; end if;
end process;
sel<=selsig;
seg(7 downto 0)<=segsig(7 downto 0);
end behave; 




⌨️ 快捷键说明

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