EDA数字钟源程序

  • 格式:doc
  • 大小:25.50 KB
  • 文档页数:2

EDA数字钟源程序
功能,计时,清零,置数
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
entity clock is
port(clk,cr:in std_logic;
s:in std_logic_vector(2 downto 0);
sec0,sec1,min0,min1,hour0,hour1:buffer std_logic_vector(3 downto 0)); end clock;
architecture behave of clock is
signal hex0,hex1,hex2,hex3,hex4,hex5:std_logic_vector(3 downto 0);
begin
process(clk,cr,s)
begin
if cr='0' then
hex0<="0000";
hex1<="0000";
hex2<="0000";
hex3<="0000";
hex4<="0000";
hex5<="0000";
elsif clk'event and clk='1' then
case s is
when "000"=>
if hex2="1001" then
hex2<="0000";
else hex2<=hex2+1;
end if;
when "001"=>
if hex3="0101" then
hex3<="0000";
else hex3<=hex3+1;
end if;
when "010"=>
if hex4="1001" then
hex4<="0000";
else hex4<=hex4+1;
end if;
when "011"=>
if hex5="0010" then
hex5<="0000";
else hex5<=hex5+1;
end if;
when "100"=>
if hex0="1001" then
hex0<="0000";hex1<=hex1+1;
if hex1="0101" then
hex1<="0000";hex2<=hex2+1;
if hex2="1001" then
hex2<="0000";hex3<=hex3+1;
if hex3="0101" then
hex3<="0000";hex4<=hex4+1;
if hex5="0010" then
if hex4="0011" then
hex4<="0000";hex5<="0000";
else
hex4<=hex4+1;
end if;
else
if hex4="1001" then
hex4<="0000";hex5<=hex5+1;
else
hex4<=hex4+1;
end if;
end if;
else hex3<=hex3+1;
end if;
else hex2<=hex2+1;
end if;
else hex1<=hex1+1;
end if;
else hex0<=hex0+1;
end if;
when others=>NULL;
end case;
end if;
end process;
sec0<=hex0;
sec1<=hex1;
min0<=hex2;
min1<=hex3;
hour0<=hex4;
hour1<=hex5;
end behave;。