You are on page 1of 6

library ieee;

use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
entity sz is
port
(
clk ,enb,key,key1,key2,clr:in std_logic ;
sk: out integer range 0 to 8;
Q:out std_logic_vector (7 downto 0);
s: out std_logic_vector (7 downto 0);
test:out std_logic);
end entity sz;
architecture one of sz is
signal cnt_1k : integer range 0 to 50000 ;
signal compete_1ms: std_logic;
signal flag_fp,min_fp,hour_fp: std_logic;
signal flag_1s,flag_1k,sec_flag ,min_flag : std_logic :='0';
signal smiao :integer range 0 to 8;
signal sec_cnt,min_cnt,num1,cnt_num :integer range 0 to 60; signal hour_cnt
:integer range 0 to 24;
signal sc_L ,sc_h,min_L ,min_h,hour_L,hour_H :integer range 0 to 9;
signalsc_L_q ,sc_h_q,min_L_q ,min_h_q,hour_L_q,hour_H_q :std_logic_vector( 7
downto 0);
begin
process (clk)
begin
if clk'event and clk ='1' then
cnt_1k<=cnt_1k+1;
if cnt_1k =50000 then
cnt_1k<=0;
compete_1ms<='1';
else
if cnt_1k<25000 then
flag_1k<='0';
else
flag_1k<='1';
end if;
compete_1ms<='0';
end if;
end if;
end process;
-- 1s
process (compete_1ms)

variable cnt_1s: integer range 0 to 1000;


begin
if compete_1ms'event and compete_1ms='1' then
cnt_1s :=cnt_1s +1;
if cnt_1s =1000 then cnt_1s :=0;
else if cnt_1s<500 then flag_1s<='0';
else flag_1s<='1';
end if;
end if;
end if;
test<=flag_1s;
end process;
--
process (enb ,key,flag_1s)
begin
if enb='1' then
flag_fp<=flag_1s;--enb
else
flag_fp<=not key;
end if;
end process;
process (enb ,key1,sec_flag)
begin
if enb='1' then
min_fp<=sec_flag;--enb
else
min_fp<=not key1;
end if;
-- test<=min_fp;
end process;
process (enb ,key2,min_flag)
begin
if enb='1' then
hour_fp<=min_flag;
else
hour_fp<=not key2;
end if;
-- test<=hour_fp;
end process;
--
process(flag_fp)

begin
if flag_fp'event and flag_fp='1' then
if sec_cnt=59 then sec_cnt<=0; sec_flag<='1';else sec_cnt<=sec_cnt+1 ; sec_flag<='0';
end if;
end if;
sc_L <=sec_cnt mod 10;
sc_h<= integer (sec_cnt/10);
end process;
--
process(min_fp)
begin
--if enb='1' then
if min_fp'event and min_fp='1' then
if min_cnt=59 then min_cnt<=0; min_flag<='1';else min_cnt<=min_cnt+1; min_flag<='0';
end if;
end if;
-- end if;
min_L <= min_cnt mod 10;
min_h<= integer(min_cnt/10)
end process;
--
process(hour_fp)
begin
-- if enb='1' then
if hour_fp'event and hour_fp='1' then
if hour_cnt =23 then hour_cnt<=0;
else hour_cnt<=hour_cnt +1;
end if;
end if;
hour_L <= hour_cnt mod 10;
hour_h<= integer (hour_cnt/10);
end process;
--
process (flag_1k)
begin
if flag_1k'event and flag_1k='1' then
if smiao=7 then smiao<=0;
else smiao<=smiao+1;
end if;

end if;
sk<=smiao;
end process;
--
PROCESS(sc_l,sc_h,min_l,min_h,hour_l,hour_h)
BEGIN
--
CASE(sc_l) IS
WHEN 0 => sc_l_q<="00000011";
WHEN 1 => sc_l_q<="10011111";
WHEN 2 => sc_l_q<="00100101";
WHEN 3 => sc_l_q<="00001101";
WHEN 4 => sc_l_q<="10011001";
WHEN 5 => sc_l_q<="01001001";
WHEN 6 => sc_l_q<="01000001";
WHEN 7 => sc_l_q<="00011111";
WHEN 8 => sc_l_q<="00000001";
WHEN 9 => sc_l_q<="00001001";
WHEN OTHERS => NULL;
END CASE;
--
CASE(sc_h) IS
WHEN 0 => sc_h_q<="00000011";
WHEN 1 => sc_h_q<="10011111";
WHEN 2 => sc_h_q<="00100101";
WHEN 3 => sc_h_q<="00001101";
WHEN 4 => sc_h_q<="10011001";
WHEN 5 => sc_h_q<="01001001";
WHEN OTHERS => NULL;
END CASE;
--
CASE(min_l) IS
WHEN 0 => min_l_q<="00000011";
WHEN 1 => min_l_q<="10011111";
WHEN 2 => min_l_q<="00100101";
WHEN 3 => min_l_q<="00001101";
WHEN 4 => min_l_q<="10011001";
WHEN 5 => min_l_q<="01001001";
WHEN 6 => min_l_q<="01000001";
WHEN 7 => min_l_q<="00011111";
WHEN 8 => min_l_q<="00000001";
WHEN 9 => min_l_q<="00001001";
WHEN OTHERS => NULL;

END CASE;
--
CASE(min_h) IS
WHEN 0 => min_h_q<="00000011";
WHEN 1 => min_h_q<="10011111";
WHEN 2 => min_h_q<="00100101";
WHEN 3 => min_h_q<="00001101";
WHEN 4 => min_h_q<="10011001";
WHEN 5 => min_h_q<="01001001";
WHEN OTHERS => NULL;
END CASE;
--
CASE(hour_l) IS
WHEN 0 => hour_l_q<="00000011";
WHEN 1 => hour_l_q<="10011111";
WHEN 2 => hour_l_q<="00100101";
WHEN 3 => hour_l_q<="00001101";
WHEN 4 => hour_l_q<="10011001";
WHEN 5 => hour_l_q<="01001001";
WHEN 6 => hour_l_q<="01000001";
WHEN 7 => hour_l_q<="00011111";
WHEN 8 => hour_l_q<="00000001";
WHEN 9 => hour_l_q<="00001001";
WHEN OTHERS => NULL;
END CASE;
--
CASE(hour_h) IS
WHEN 0 => hour_h_q<="00000011";
WHEN 1 => hour_h_q<="10011111";
WHEN 2 => hour_h_q<="00100101";
WHEN OTHERS => NULL;
END CASE;
END PROCESS;
--
PROCESS(smiao)
BEGIN
CASE smiao IS
WHEN 0 => S<="01111111";Q<=sc_l_q;
WHEN 1 => S<="10111111";Q<=sc_h_q;
WHEN 2 => S<="11011111";Q<="11111101";
WHEN 3 => S<="11101111";Q<=min_l_q;
WHEN 4 => S<="11110111";Q<=min_h_q;
WHEN 5 => S<="11111011";Q<="11111101";
WHEN 6 => S<="11111101";Q<=hour_l_q;

WHEN 7 => S<="11111110";Q<=hour_h_q;


WHEN OTHERS => NULL;
END CASE;
end process;
end architecture one;

You might also like