
vhdl 的 数字时钟代码
是笔者写过的一个液晶显示时钟改成的数码管显示时钟,已经通过编译,不过没有硬件实践,
(液晶显示通过了硬件验证)。你可以验证一下!另带有时间调整功能,如不需要可删除。
(时钟频率可自行修改成 1s)
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;
entity try is
port(clk,reset:in std_logic; --时钟信号和复位信号
setmin,sethour,setsec:in std_logic;
a1,a0:in std_logic_vector(3 downto 0);
yout:out std_logic_vector(7 downto 0);
sel:out std_logic_vector(2 downto 0)
);
end try;
architecture a of try is
signal Q5,Q4,Q3,Q2,Q1,Q0 :std_logic_vector(3 downto 0);
signal enmin,enhour :std_logic; --触发信号
signal q:std_logic_vector(21 downto 0); --分频信号
signal clks,clkscan: std_logic;
type state is (s0,s1,s2,s3,s4,s5);
signal p_state,n_state:state;
signal y:std_logic_vector(7 downto 0);
signal selout:std_logic_vector(2 downto 0);
signal yy:std_logic_vector(3 downto 0);
begin
process (clk) is --分频
begin
if clk'event and clk='1' then
if q=2499999 then --choose 5MHz
q<="0000000000000000000000"; --22 位
clks<=not clks; --1s
else
q<=q+'1';
end if;
clkscan<=q(8); --扫描时钟
end if;
end process;
second:process (clks) is
begin
if reset='1' then
评论1