扩展到时分秒。加了入调时电路,但不知道为什么有两个按键不好使。而且不知道以何种方式假如按键消抖电路,因为加入后会多个时钟控制一个信号,物理不可实现。调试电路待解决。还有,四个数目管中间的那两个圆点怎么点亮啊,没有地址啊,求破。待我清明之后解决这个问题。

下面是代码。

 library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL; entity clock is
Port ( clk : in STD_LOGIC;
sw0: in STD_LOGIC;
btn : in STD_LOGIC_VECTOR ( downto );
led0: out STD_LOGIC;
seg : out STD_LOGIC_VECTOR ( downto );
seg7:out STD_LOGIC;
an : out STD_LOGIC_VECTOR ( downto ));
end clock; architecture Behavioral of clock is
signal num:STD_LOGIC_VECTOR ( downto );
signal hour_h:STD_LOGIC_VECTOR ( downto );
signal hour_l:STD_LOGIC_VECTOR ( downto );
signal min_h:STD_LOGIC_VECTOR ( downto );
signal min_l:STD_LOGIC_VECTOR ( downto );
signal second_h:STD_LOGIC_VECTOR ( downto );
signal second_l:STD_LOGIC_VECTOR ( downto );
signal an_sel:STD_LOGIC_VECTOR ( downto );
signal cnt: INTEGER;
signal cnt2: INTEGER;
signal sclk: STD_LOGIC;
signal aclk: STD_LOGIC;
signal shine:STD_LOGIC;
begin
led0<=shine;
process(clk)
begin
if(clk'event and clk='') then
if(cnt=) then
cnt<=;
sclk<=not sclk;
else
cnt<=cnt+;
end if;
end if;
end process; process(clk)
begin
if(clk'event and clk='') then
if(cnt2=) then
cnt2<=;
if(an_sel="") then
an_sel<="";
else
an_sel<=an_sel+'';
end if;
else
cnt2<=cnt2+;
end if;
end if;
end process; process(sclk,sw0,btn)
begin
if(sw0='') then
if(btn()='') then
second_l<=second_l+'';
end if;
if(btn()='') then
second_h<=second_h+'';
end if;
if(btn()='') then
hour_l<=hour_l+'';
end if;
if(btn()='') then
hour_h<=hour_h+'';
end if;
else
if(sclk'event and sclk='') then
shine<=second_l();
if(second_h="" and second_l="") then
second_h<="";
second_l<="";
min_l<=min_l+'';
if(min_h="" and min_l="") then
min_h<="";
min_l<="";
hour_l<=hour_l+'';
if(hour_h="" and min_l="") then
hour_h<="";
hour_l<="";
elsif(hour_l="")then
hour_h<=hour_h+'';
hour_l<="";
end if;
elsif(min_l="") then
min_h<=min_h+'';
min_l<="";
end if;
elsif(second_l="") then
second_h<=second_h+'';
second_l<="";
else
second_l<=second_l+'';
end if;
end if;
end if;
end process; process(an_sel,second_l,second_h,min_l,min_h,hour_l,hour_h)
begin
case an_sel is
when ""=>an<="";num<=min_l;seg7<='';
when ""=>an<="";num<=min_h;seg7<='';
when ""=>an<="";num<=hour_l;seg7<='';
when ""=>an<="";num<=hour_h;seg7<='';
when others=>null;
end case;
case num is
when x""=>seg<=b"";
when x""=>seg<=b"";
when x""=>seg<=b"";
when x""=>seg<=b"";
when x""=>seg<=b"";
when x""=>seg<=b"";
when x""=>seg<=b"";
when x""=>seg<=b"";
when x""=>seg<=b"";
when x""=>seg<=b"";
when others=>null;
end case;
end process;
end Behavioral;

约束文件

 NET "clk" LOC = "B8";
NET "led0" LOC ="M5";
NET "an<0>" LOC="K14";
NET "an<1>" LOC="M13";
NET "an<2>" LOC="J12";
NET "an<3>" LOC="F12";
NET "seg7" LOC="N13";
NET "seg<6>" LOC="L14";
NET "seg<5>" LOC="H12";
NET "seg<4>" LOC="N14";
NET "seg<3>" LOC="N11";
NET "seg<2>" LOC="P12";
NET "seg<1>" LOC="L13";
NET "seg<0>" LOC="M12";
NET "btn<0>" LOC = "G12";
NET "btn<1>" LOC = "C11";
NET "btn<2>" LOC = "M4";
NET "btn<3>" LOC = "A7";
NET "sw0" LOC="P11";
05-22 04:29