You are on page 1of 6

library ieee;

use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;

entity counter is
port (clk : in std_logic;
up_down : in std_logic;
temp1 : buffer std_logic_vector(0 to 3);
temp2 : buffer std_logic_vector(0 to 3));
end counter;

architecture arch of counter is

begin

process (clk)

con siete segmentos :
library ieee;

use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;

entity counter is
port (clk : in std_logic;
up_down : in std_logic;
segment1 : out std_logic_vector(0 to 6);
segment2 : out std_logic_vector(0 to 6));
end counter;

architecture arch of counter is
SIGNAL temp1,temp2: std_logic_vector(0 to 3);


begin

process (clk)
begin
if clk'event and clk = '1' then
if up_down='1' then
temp1 <=temp1 + 1;
IF (temp1="1001") THEN
temp1 <="0000";
temp2<= temp2 + 1;
IF (temp2="1001") THEN
temp2<="0000";
END IF;
END IF;
ELSE
temp1<=temp1 - 1;
IF (temp1="0000") THEN
temp1 <="1001";
temp2<=temp2 - 1;
IF (temp2="0000") THEN
temp2 <="1001";
END IF;
END IF;

END IF;
END IF;

case temp1 is
when "0000"=> segment1 <="0000001"; -- '0'
when "0001"=> segment1 <="1001111"; -- '1'
when "0010"=> segment1 <="0010010"; -- '2'
when "0011"=> segment1 <="0000110"; -- '3'
when "0100"=> segment1 <="1001100"; -- '4'
when "0101"=> segment1 <="0100100"; -- '5'
when "0110"=> segment1 <="0100000"; -- '6'
when "0111"=> segment1 <="0001111"; -- '7'
when "1000"=> segment1 <="0000000"; -- '8'
when "1001"=> segment1 <="0000100"; -- '9'
when others=> segment1 <="1111111";
end case;

case temp2 is
when "0000"=> segment2 <="0000001"; -- '0'
when "0001"=> segment2 <="1001111"; -- '1'
when "0010"=> segment2 <="0010010"; -- '2'
when "0011"=> segment2 <="0000110"; -- '3'
when "0100"=> segment2 <="1001100"; -- '4'
when "0101"=> segment2 <="0100100"; -- '5'
when "0110"=> segment2 <="0100000"; -- '6'
when "0111"=> segment2 <="0001111"; -- '7'
when "1000"=> segment2 <="0000000"; -- '8'
when "1001"=> segment2 <="0000100"; -- '9'
when others=> segment2 <="1111111";
end case;

end process;

end arch;



begin
if clk'event and clk = '1' then
if up_down='1' then
temp1 <=temp1 + 1;
IF (temp1="1001") THEN
temp1 <="0000";
temp2<= temp2 + 1;
IF (temp2="1001") THEN
temp2<="0000";
END IF;
END IF;
ELSE
temp1<=temp1 - 1;
IF (temp1="0000") THEN
temp1 <="1001";
temp2<=temp2 - 1;
IF (temp2="0000") THEN
temp2 <="1001";
END IF;
END IF;

END IF;
END IF;

end process;

end arch;

You might also like