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

📄 zuiniuclock.txt

📁 基本数字表功能 动态扫描显示 有闹钟功能 秒表功能
💻 TXT
字号:
LIBRARY IEEE; 
USE IEEE.STD_LOGIC_1164.ALL; 
USE IEEE.STD_LOGIC_ARITH.ALL; 
USE IEEE.STD_LOGIC_UNSIGNED.ALL; 
USE IEEE.STD_LOGIC_UNSIGNED; 

ENTITY mutiwatch IS 
PORT(clk,scanclk,clr,clock,sclock,pause,m_add,h_add,mclock,hclock:IN STD_LOGIC; 
alarm:OUT STD_LOGIC; 
--led:OUT STD_LOGIC_VECTOR(7 DOWNTO 0); 
leda:OUT STD_LOGIC_VECTOR(7 DOWNTO 0); 
disout:out std_logic_vector(2 downto 0);
hourhigh:out STD_LOGIC_VECTOR(3 DOWNTO 0));
END mutiwatch ; 

ARCHITECTURE Behavioral OF mutiwatch IS 
SIGNAL clk_div2,clk_div1:STD_LOGIC_VECTOR(9 DOWNTO 0); 
SIGNAL clk_div3:STD_LOGIC_VECTOR(4 DOWNTO 0); 
SIGNAL clk0,clk1,noalarm:STD_LOGIC; 
SIGNAL hh,hl,mh,ml,sh,sl,ob,oh,ol:STD_LOGIC_VECTOR(3 DOWNTO 0);
SIGNAL shh,shl,smh,sml,ss:STD_LOGIC_VECTOR(3 DOWNTO 0);--for alarm
SIGNAL ssh,ssl,fs,msh,msl:STD_LOGIC_VECTOR(3 DOWNTO 0);--for the second counter
SIGNAL num:STD_LOGIC_VECTOR(3 DOWNTO 0); 
SIGNAL numh:STD_LOGIC_VECTOR(3 DOWNTO 0); 
SIGNAL led1:STD_LOGIC_VECTOR(3 DOWNTO 0); 
SIGNAL led2:STD_LOGIC_VECTOR(3 DOWNTO 0);
SIGNAL dispcnt:STD_LOGIC_VECTOR(2 DOWNTO 0);


BEGIN 
u1:PROCESS(clk) ----generate clk
BEGIN 
IF rising_edge(clk) THEN 
clk_div1<=clk_div1+'1'; 
IF ( clk_div1 = "1111101000")THEN 
clk_div1 <= (others=>'0'); 
clk_div3<=clk_div3+'1'; 
END IF; 
IF( clk_div3 = "01010") THEN --40000feipin
clk0 <= NOT clk0; ----generate 1ms signal , and 40MHZ -> clk
clk_div3 <= (others=>'0'); 
clk_div2<=clk_div2+'1'; 
END IF; 
IF( clk_div2 = "1111101000") THEN 
clk_div2 <= (others=>'0'); 
clk1 <= NOT clk1; ---generate 1s signal 
END IF; 
END IF; 
END PROCESS u1; 


u2:PROCESS(clk0,clr) ---create 1000 ms for the time_play
BEGIN 
IF(clr='1')AND(sclock = '0')THEN 
ol<="0000"; 
oh<="0000"; 
ob <="0000"; 
ELSIF rising_edge(clk0) THEN 
IF (ol="1001") THEN 
IF(oh="1001")THEN 
if(ob="1001")THEN 
ob<="0000"; 
ELSE 
ob<=ob+'1'; 
END IF; 
oh<="0000"; 
ELSE 
oh<=oh+'1'; 
END IF; 
ol<="0000"; 
ELSE 
ol<=ol+'1'; 
END IF; 
END IF; 

END PROCESS u2; 


u3:PROCESS(clk1,clr,ob,oh,ol) ---create 60 s for the time_play
BEGIN 
IF(clr='1')AND(sclock = '0')THEN 
sl<="0000"; 
sh<="0000"; 
ELSIF rising_edge(clk0)THEN 
IF((ob="1001")AND(oh="1001")and(ol="1001")and(h_add = '0')and(m_add= '0') )THEN 
IF((sh="0101")AND(sl="1001"))THEN 
sl<="0000"; sh<="0000";
ELSE if sl="1001"then
sh<=sh+'1'; --
sl<="0000"; 
ELSE 
sl<=sl+'1'; 
END IF; 
END IF; 
end if;
end if;
END PROCESS u3; 

u4:PROCESS(clk1,clr,sh,sl,m_add) --create 60 munites for the time_play
BEGIN 
IF (clr='1')AND(sclock = '0')then
ml<="0000"; 
mh<="0000"; 
ELSIF rising_edge(clk1)THEN 
IF(((sh="0101")AND(sl="1001"))OR(m_add='1'))THEN 
IF((mh="0101")AND(ml="1001"))THEN --
mh<="0000";ml<="0000"; --
ELSIF ml="1001" THEN 
mh <= mh+'1'; 
ml <= "0000"; 
ELSE 
ml<=ml+'1'; 
END IF; 
END IF; 
END IF; 
END PROCESS u4; 


u5:PROCESS(clk1,clr,mh,ml,sh,sl,h_add) --create 24 hours for the time_play
BEGIN 
IF (clr='1')AND(sclock = '0')THEN 
hl<="0000"; 
hh<="0000"; 
ELSIF rising_edge(clk1)THEN 
IF(((sh="0101")AND(sl="1001")AND(mh="0101")AND(ml="1001"))OR(h_add='1'))THEN 
IF((hh="0010")AND(hl="0011"))THEN 
hh<="0000";hl<="0000"; 
ELSIF(hl="1001")THEN 
hh <= hh +'1'; 
hl <= "0000"; 
ELSE 
hl<=hl+'1'; 
END IF; 
END IF; 
END IF; 
END PROCESS u5; 


u6:PROCESS(clk0,clr,sclock) ---creat ms for the second_counter
BEGIN 
IF (clr='1')AND(sclock='1') THEN 
msl<="0000"; 
msh<="0000"; 
fs <="0000"; 
elsIF rising_edge(clk0) THEN 
IF sclock = '1' THEN 
IF (msl="1001")AND(pause='0') THEN 
IF(msh="1001")THEN 
if(fs="1001")THEN 
fs<="0000"; 
ELSE 
fs<=fs+'1'; 
END IF; 
msh<="0000"; 
ELSE 
msh<=msh+'1'; 
END IF; 
msl<="0000"; 
ELSE 
msl<=msl+'1'; 
END IF; 
END IF; 
END IF; 
END PROCESS u6; 

u7:PROCESS(clk0,clr,msh,msl,fs,sclock) --s 计数器 
BEGIN 
IF (clr='1')AND(sclock='1')THEN 
ssl<="0000"; 
ssh<="0000"; 
ELSIF rising_edge(clk0)THEN 
IF (sclock = '1')AND(pause='0')THEN 
IF((fs="1001")AND(msh="1001")AND(msl="1001"))THEN 
IF((ssh="0101")AND(ssl="1001"))THEN 
ssh<="0000";ssl<="0000"; 
ELSIF(ssl="1001")THEN 
ssh <= ssh +'1'; 
ssl <= "0000"; 
ELSE 
ssl<=ssl+'1'; 
END IF; 
END IF; 
END IF; 
END IF; 
END PROCESS u7; 

u8:PROCESS(clock,clk1) ---设置闹钟分 
BEGIN  
IF rising_edge( clk1 ) THEN
IF ( ( clock = '1')AND(mclock = '1')) THEN 
IF(( smh = "0101" )and(sml="1001")) THEN 
smh <="0000"; sml<="0000";
ELSE if sml="1001"then
smh<=smh+'1';
sml <= "0000";
else
sml <= sml+'1'; 
END IF; 
END IF; 
end if;
end if;

end process u8;

u100:process(clock,clk1)
begin
IF rising_edge( clk1 ) THEN
IF (( clock = '1') AND (hclock = '1'))THEN 
IF( (shh="0010")AND(shl ="0011") ) THEN --------------
shh <= "0000";shl <= "0000"; 
ELSIF(shl="1001") THEN 
shh <= shh+'1'; 
shl <= "0000"; 
ELSE 
shl <= shl + '1'; 
END IF; 
END IF; 
END IF; 

END PROCESS u100; 


u9:PROCESS(clk1) --闹钟音乐 
BEGIN 
IF rising_edge( clk1 ) THEN 
IF((shl = hl )AND(shh = hh)AND(sml = ml )AND(smh = mh)AND(noalarm = '0')) THEN 
alarm <= '1'; 
ss <= sml + "0001"; 
IF (clock = '1') THEN 
alarm <= '0'; 
noalarm <= '1'; 
END IF; 
END IF; 
IF(ml = ss) THEN --the alarm will last for one munite 
alarm <= '0'; 
noalarm <= '0'; 
END IF; 
END IF; 
END PROCESS u9; 

u10: PROCESS(scanclk) 
BEGIN  
IF rising_edge(scanclk)THEN 
    dispcnt<=dispcnt+1;  ---IF OVER 9,THE SIGNAL WILL OUT(YICHU)
END  IF;
disout<=dispcnt;
end process u10;


u11: PROCESS(dispcnt,clock,sclock) 
BEGIN 
IF ( clock='1') THEN 
IF dispcnt="101"THEN 
num<=shh; 
ELSIF dispcnt="100"THEN 
num<=shl; 
ELSIF dispcnt="010"THEN 
num<=smh; 
ELSIF dispcnt="001"THEN 
num<=sml;
else num<="0000";
END IF;
ELSIF (sclock = '1')THEN 
IF dispcnt="100"THEN 
num<=ssh; 
ELSIF dispcnt="011"THEN 
num<=ssl; 
ELSIF dispcnt="010"THEN 
num<=fs; 
ELSIF dispcnt="001"THEN 
num<=msh; 
ELSIF dispcnt="000"THEN
num<=msl;
else num<="0000";
END IF; 
ELSE --the part of diplaying the time ( changed)
hourhigh<=hh;---------------
IF dispcnt="111"THEN 
num<=hl; 
ELSIF dispcnt="110"THEN 
num<=mh; 
ELSIF dispcnt="101"THEN 
num<=ml; 
ELSIF dispcnt="100"THEN 
num<=sh; 
ELSIF dispcnt="011"THEN 
num<=sl; 
ELSIF dispcnt="010"THEN 
num<=ob; 
ELSIF dispcnt="001"THEN 
num<=oh; 
ELSIF dispcnt="000"THEN 
num<=ol; 

END IF; 
END IF; 
END PROCESS u11; 


 
WITH num SELECt
leda<="00000110"WHEN"0001", --1 
"01011011"WHEN"0010", --2 
"01001111"WHEN"0011", --3 
"01100110"WHEN"0100", --4 
"01101101"WHEN"0101", --5 
"01111101"WHEN"0110", --6 
"00000111"WHEN"0111", --7 
"01111111"WHEN"1000", --8 
"01101111"WHEN"1001", --9 
"00111111"WHEN OTHERS; --0 


END behavioral; 

⌨️ 快捷键说明

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