-- 74163 FULLY SYNCHRONOUS COUNTER

library BITLIB;			-- contains int2vec and vec2int functions
use BITLIB.bit_pack.all;

entity c74163 is
   port(LdN, ClrN, P, T, CK: in bit;  D: in bit_vector(3 downto 0);
        Cout: out bit; Q: inout bit_vector(3 downto 0) );
end c74163;

architecture b74163 of c74163 is
begin
   Cout <= Q(3) and Q(2) and Q(1) and Q(0) and T;
   process
   begin
      wait until CK = '1';		-- change state on rising edge
      if ClrN = '0' then  Q <= "0000";
         elsif LdN = '0' then Q <= D;
         elsif (P and T) = '1' then  
           Q <= int2vec(vec2int(Q)+1,4);
      end if;
   end process;
end b74163;		
