M=60的计数器

--具有异步复位、同步置数和使能的递增BCD码计数器

--module=60

library   ieee;

use   ieee.std_logic_1164.all;

use   ieee.std_logic_unsigned.all;

entity cntm60 is

port (ci         :in  std_logic;

        nrest    :in  std_logic;

        load      :in  std_logic;

        d          :in  std_logic_vector(7 downto 0);

        clk        :in  std_logic;

        co        :out  std_logic; 

        qh        :buffer  std_logic_vector(3 downto 0);

        ql        :buffer  std_logic_vector(3 downto 0));

end cntm60;

 

architecture behave of cntm60 is

 begin

 co<='1'  when  (qh="0101" and al="1001" and ci='1')  else '0';

 process(clk,nrest)

 begin

   if(nrest='0')  then

      qh<="0000";

      ql<="0000";

  elsif (clk'event and clk='1')  then

  if  (load='1')  then

      qh<=d(7 downto 4);

      ql<=d(3 downto 0);

  elsif (ci='1') then

      if(ql=9)  then

          ql<="0000"

            if(qh=5) then

             qh<="0000";

            else 

              qh<=qh+1;

            end if;

        else 

           ql<=ql+1;

        end if;

   end if;

end if;

   end process;

 end behave;

posted on 2009-10-21 11:35  月朗星稀  阅读(306)  评论(0编辑  收藏  举报

导航