基本功能: 实现24小时制的计时,整点报时,小时和分钟可调.
8位数码管显示,12位显示小时,3位显示一杠,45显示分钟,6显示一杠,78显示秒.
调时的时候数码管随着时钟明暗闪烁.
这个是考试前的一段时间的EDA实验的设计性实验,因为要准备考试的事,没多少时间做更好的处理,所以没有做按键去抖动的部分处理.
LIBRARY IEEE;
USE IEEE.STD_LOGIC_1164.ALL;
USE IEEE.STD_LOGIC_UNSIGNED.ALL;
ENTITY szz2 IS
PORT( clk,SZm,szh,SCLK,sansuo:IN STD_LOGIC;
CLEAR:IN STD_LOGIC;
spk:OUT STD_LOGIC;
Q:OUT STD_LOGIC_VECTOR(6 DOWNTO 0);
SEL:OUT STD_LOGIC_VECTOR(2 DOWNTO 0));
END ;
--SCLK is the counter's driver
--SZm and szh is connect to two switch , which control the adjust of minter and hour
--clk is the driver of the led_7 's refresh
ARCHITECTURE behav OF szz2 IS
SIGNAL SELI:STD_LOGIC_VECTOR(2 DOWNTO 0);
SIGNAL P,PL1,PL2,PL3,PH1,PH2,PH3:std_logic_vector(3 downto 0);
SIGNAL MCLK,HCLK,CLKM,CLKH,sanfen,sanshi:STD_LOGIC;
BEGIN
P_JISHU1:PROCESS (SCLK,CLEAR)
VARIABLE tmpl,tmph :std_logic_vector(3 downto 0);
BEGIN
IF CLEAR='1' THEN
tmpl:="0000";
tmph:="0000";
ELSIF (SCLK'EVENT AND SCLK = '1') THEN
if (tmpl="1001") then
tmpl:="0000";
if(tmph="0101") then
tmph:="0000"; MCLK<='1';
else
tmph:=tmph+1;
end if;
else
tmpl:=tmpl+1; MCLK<='0';
end if;
end IF;
PL1<= tmpL;
PH1<=tmph;
END PROCESS P_JISHU1;
P_JISHU2:PROCESS (CLKM,CLEAR,SZm,SCLK,MCLK)
VARIABLE tmpl,tmph:std_logic_vector(3 downto 0);
BEGIN
IF (SZm='1') THEN CLKM<=SCLK;sanfen<='1';
ELSE CLKM<=MCLK;sanfen<='0';
END IF;
IF (CLEAR='1') THEN
tmpl:="0000";
tmph:="0000";
ELSIF (CLKM'EVENT AND CLKM = '1') THEN
if (tmpl="1001") then
tmpl:="0000";
if(tmph="0101") then
tmph:="0000"; HCLK<='1';
else
tmph:=tmph+1;
end if;
else
tmpl:=tmpl+1; HCLK<='0';
end if;
end IF;
PL2<= tmpL;
PH2<=tmph;
END PROCESS P_JISHU2;
P_JISHU3:PROCESS (CLKH,CLEAR,SZh,SCLK,HCLK)
VARIABLE tmpl,tmph :std_logic_vector(3 downto 0);
BEGIN
IF SZh='1' THEN CLKH<=SCLK;sanshi<='1';
ELSE CLKH<=HCLK ;sanshi<='0';
END IF;
IF CLEAR='1' THEN
tmpl:="0000";
tmph:="0000";
ELSIF (CLKH'EVENT AND CLKH = '1') THEN
if (tmpl="0011" and tmph="0010" ) or (tmpl="1001")then
tmpl:="0000";
if(tmph="0010") then
tmph:="0000";
else
tmph:=tmph+1;
end if;
else
tmpl:=tmpl+1;
end if;
end IF;
PL3<= tmpL;
PH3<=tmph;
END PROCESS P_JISHU3;
P_SEL:PROCESS(CLK,CLEAR,SELI)--clk is driver the led_7 's refresh
BEGIN
IF CLEAR='1' THEN SELI<="000";
ELSIF CLK'EVENT AND CLK='1' THEN
IF (SELI="111") THEN SELI<="000";
ELSE
SELI<=SELI+1;
END IF;
END IF;
SEL<=SELI;
END PROCESS P_SEL;
P_XUANZE:PROCESS(SELI,PL1,PH1,PL2,PH2,PL3,PH3)
BEGIN
CASE SELI IS
WHEN "000"=>p<=PL1;
WHEN "001"=>p<=PH1;
WHEN "010"=>p<="1010";
WHEN "011"=>if (sanfen='1') then
if(sansuo= '1') then p<=PL2;
else p<="1011";
END IF;
else p<=PL2;
END IF;
WHEN "100"=>if (sanfen='1') then
if(sansuo= '1') then p<=PH2;
else p<="1011";
END IF;
else p<=PH2;
END IF;
WHEN "110"=>if (sanshi='1') then
if(sansuo= '1') then p<=PL3;
else p<="1011";
END IF;
else p<=PL3;
END IF;
WHEN "111"=>if (sanshi='1') then
if(sansuo= '1') then p<=PH3;
else p<="1011";
END IF;
else p<=PH3;
END IF;
WHEN "101"=>p<="1010";
-- WHEN "110"=>p<=PL3;
-- WHEN "111"=>p<=PH3;
WHEN OTHERS=>NULL;
END CASE;
END PROCESS P_XUANZE;
P_XIAN:PROCESS(P)
BEGIN
CASE P IS
WHEN "0000" => Q<="0111111";
WHEN "0001" => Q<="0000110";
WHEN "0010" => Q<="1011011";
WHEN "0011" => Q<="1001111";
WHEN "0100" => Q<="1100110";
WHEN "0101" => Q<="1101101";
WHEN "0110" => Q<="1111101";
WHEN "0111" => Q<="0000111";
WHEN "1000" => Q<="1111111";
WHEN "1001" => Q<="1101111";
WHEN "1011" => Q<="0000000";
WHEN "1010" => Q<="1000000";
WHEN OTHERS => NULL ;
END CASE;
END PROCESS P_XIAN;
PROCESS(ph2,pl2)
BEGIN
IF(ph2="0000" and pl2="0000") THEN
spk<='1';
ELSE spk<='0';
END IF ;
END PROCESS;
END behav ;
文章评论(0条评论)
登录后参与讨论