基于vhdl时钟的设计与制作(附完整代码)

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

三、实验程序及部分仿真波形图

library ieee;

use ieee.std_logic_1164.all;

use ieee.std_logic_unsigned.all;

entity colock is

port(clk1,clk2,key1,key2: in std_logic;

abc:out std_logic_vector(2 downto 0);

led7s:out std_logic_vector(6 downto 0) );

end entity;

architecture one of colock is

signal ctrl:std_logic_vector(3 downto 0);

signal clk02,cs02,cm02,cs1,cs2,cm1,cm2,ch1,cp,k2,ck1,ck2:std_logic;

signal s1,s2,m1,m2,h1,h2,s01,s02,m01,m02,h01,h02,s001,s002,m001,m002,h001, h002,p1,p2,disp:std_logic_vector(3 downto 0);

signal ctrl0:std_logic_vector(8 downto 0);

signal tmp1,tmp2:std_logic_vector(9 downto 0);

signal k1:std_logic_vector(1 downto 0);

begin

--当处于按键调时状态时,根据K1的值来确定所调整的位,被调整的位送按键2产生的脉冲(CK2),其余进位脉冲赋0屏蔽掉

process(k1,clk2,clk02,cs2,cm2,ck2)

begin

case k1 is

when "00" => clk02<=clk2;cs02<=cs2;cm02<=cm2;

when "01" => clk02<=ck2;cs02<='0';cm02<='0';

when "10" => clk02<='0';cs02<=ck2;cm02<='0';

when "11" => clk02<='0';cs02<='0';cm02<=ck2;

when others => clk02<=clk2;cs02<=cs2;cm02<=cm2;

end case ;

end process;

--500进制计数器,每500ms对CP进行取反一次,用于闪烁控制

process(clk1)

begin

if rising_edge(clk1) then

if ctrl0<499 then ctrl0<=ctrl0+1;

else ctrl0<="000000000";cp<=not cp;

end if;

end process;

--数码管动态扫描,接138的输入端

process(clk1)

begin

if rising_edge(clk1) then

if ctrl<9 then ctrl<=ctrl+1;

else ctrl<="0000";

end if ;

end if ;

end process;

abc<=ctrl(2 downto 0);

--秒个位的计数

process(clk02)

begin

if rising_edge(clk02) then

if s01<"1001" then s01<=s01+1;cs1<='0';

else s01<="0000";cs1<='1';

end if;

end if;

end process;

--秒十位的计数

process(cs1)

begin

if rising_edge(cs1) then

if s02<"0101" then s02<=s02+1;cs2<='0';

else s02<="0000";cs2<='1';

end if;

end if;

end process;

--分个位的计数

process(cs02)

begin

if rising_edge(cs02) then

if m01<"1001" then m01<=m01+1;cm1<='0';

else m01<="0000";cm1<='1';

end if;

end if;

--分十位的计数

process(cm1)

begin

if rising_edge(cm1) then

if m02<"0101" then m02<=m02+1;cm2<='0';

else m02<="0000";cm2<='1';

end if;

end if;

end process;

--小时个位的计数

process(cm02)

begin

if rising_edge(cm02) then

if h02<"0010" then

if h01<"1001" then h01<=h01+1;ch1<='0';

else h01<="0000";ch1<='1';

end if ;

else

if h01<"0011"then h01<=h01+1;ch1<='0';

else h01<="0000";ch1<='1';

end if;

end if;

end if;

end process;

--小时十位的计数

process(ch1)

begin

if rising_edge(ch1) then

if h02<"0010" then h02<=h2+1;

else h02<="0000";

end if;

end if;

end process;

--按键一去抖动

process(clk1)

begin

if rising_edge(clk1) then

tmp1(0)<=key1;tmp1(9 downto 1)<=tmp1(8 downto 0);

相关文档
最新文档