集成电路技术分享

 找回密码
 我要注册

QQ登录

只需一步,快速开始

搜索
查看: 1735|回复: 0

简易数字钟代码 vhdl

[复制链接]
ATA 发表于 2010-6-28 01:01:57 | 显示全部楼层 |阅读模式
简易数字钟代码学校做实验用的直接输出bcd码  在外接一个数码管译码程序就可以

library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;
entity cnt is
port(clk ,rst:in std_logic;
  sa,sb,ma,mb,ha,hb

ut std_logic_vector(3 downto 0));
end ;
architecture one of cnt is
signal cnt1,cnt2 :std_logic:='0';
begin
-------------------------------秒计时-------------------
process(clk,rst)
variableqsa,qsb : std_logic_vector(3 downto 0);
begin
if rst='1' thenqsa:=(others=>'0');
       qsb:=(others=>'0');
elsif clk'event and clk='1' then
  if (qsa=9 and qsb=5)then cnt1<='1';qsa:=(others=>'0');qsb:=(others=>'0');
  elsif qsa=9then qsa:=(others=>'0');
  if qsb=5 thenqsb:=(others=>'0');
  else qsb:=qsb+1;
  end if;
elseqsa:=qsa+1;cnt1<='0';
end if;
end if;

sb<=qsb;
sa<=qsa;
end process;
----------------------------------分计时-------------------------
process(cnt1,rst)
variableqma,qmb : std_logic_vector(3 downto 0);
begin
if rst='1' thenqma:=(others=>'0');
     qmb:=(others=>'0');
elsif cnt1'event and cnt1='1' then
if (qma=9 and qmb=5)then cnt2<='1';qma:=(others=>'0');qmb:=(others=>'0');
elsif qma=9then qma:=(others=>'0');
  if qmb=5 thenqmb:=(others=>'0');
  else qmb:=qmb+1;
  end if;
else qma:=qma+1;cnt2<='0';
end if;
end if;
mb<=qmb;
ma<=qma;
end process;
------------------------------------小时计时-------------------
process(cnt2,rst)
variableqha,qhb : std_logic_vector(3 downto 0);
begin
if rst='1' thenqha:=(others=>'0');
     qhb:=(others=>'0');
elsif cnt2'event and cnt2='1' then
if (qha=3 and qhb=2) then qha:=(others=>'0');qhb:=(others=>'0');
elsifqha=9 then qha:=(others=>'0');
   if (qhb=2 and qha=3) then qhb:=(others=>'0');qha:=(others=>'0');
   else qhb:=qhb+1;
   end if;
elseqha:=qha+1;
end if;  
end if;
hb<=qhb;
ha<=qha;
end process;
end one;
您需要登录后才可以回帖 登录 | 我要注册

本版积分规则

关闭

站长推荐上一条 /1 下一条

QQ|小黑屋|手机版|Archiver|fpga论坛|fpga设计论坛 ( 京ICP备20003123号-1 )

GMT+8, 2024-12-24 03:55 , Processed in 0.059951 second(s), 19 queries .

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表