VHDL:24秒倒计时器的设计(代码完整,结构清晰,很容易看懂)

要求:

1.分频器的设计与实现。

输入为4Hz的时钟,输出为1Hz的时钟。

2.设计24秒倒计时器。

(1)输入为固定频率脉冲、使能端、复位端,输出为计时状态(用8421码表示)。

    (2)用VHDL编程实现,QuartusⅡ下编译并仿真。

具体VHDL代码实现:

--------分频器(四分频)
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;

entity clockpulse is
   port(
       CP:in std_logic;       --假设输入的是4HZ的时钟
      CO:buffer std_logic    --要求输出的是1HZ的时钟
      );
end entity clockpulse;

architecture isclockpulse of clockpulse is
signal Q : std_logic_vector(1 downto 0);
begin
   process(CP , CO)
  begin
    if(CP'event and CP = '1')  ---高电平有效
       then CO <= Q(1);  Q <= Q + '1';
      if(Q = "11") then Q <= "00";  --清零
      end if;
    end if;
  end process;
end isclockpulse;
----------计数器(25进制)
library ieee;
use ieee.std_logic_1164.ALL;
use ieee.std_logic_unsigned.all;

entity couter_25 is
port(
     CP , RESET , EN : in std_logic;
     CO: out std_logic;
     Q : out std_logic_vector(4 downto 0)
    );
end couter_25;

architecture iscouter_25 of couter_25 is
  signal iq : std_logic_vector(4 downto 0) := (others => '0');
begin
  process(CP , RESET , EN)
  begin
  if CP'event and CP = '1' then   --上升沿触发
       if RESET = '1' then    --复位端高电平清零
      iq <= "11000";  
        elsif EN = '1' then    --使能端高电平有效
      iq <= iq - '1';
      else 
      iq <= iq;
        end if;
    end if;
  end process;
  Q <= iq;
  CO <= '1' when (iq = "00000" and EN='1')
    else '0';
end iscouter_25;
-----------编码器
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
entity decode_25 is
  port( 
         D : in std_logic_vector(4 downto 0);  ---输入的5位二进制
        Q1 : out std_logic_vector(3 downto 0); ---8421BCD码的高位
        Q2 : out std_logic_vector(3 downto 0)  ---8421BXD码的低位
       );
end entity decode_25;
  
architecture isdecode_25 of decode_25 is
signal f : std_logic_vector(4 downto 0);
begin
  process(D)
  begin 
    if(D >= "00000" and D <= "01001")  then  ---D是0到9的时候
      Q1 <= "0000";
     Q2 <= D(3 downto 0);
    elsif(D <= "10011")  then  ---D是10到19的时候
      Q1 <= "0001";
     f <= (D - "01010");
     Q2 <= f(3 downto 0);
    elsif(D <= "11000")  then  ---D是20到24的时候
      Q1 <= "0010";
     f <= (D - "10100");
     Q2 <= f(3 downto 0);   ---这样就实现了0到24的二进制到8421BCD码的转换
    end if;
  end process;
end isdecode_25;

最后将这三个模块用连线的方法连接在一起就可以实现24秒倒计时器的功能啦!

评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

寥若晨星666

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值