VHDL CODE

09 June 2016

Views: 403

library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;

entity sec is
Port ( Display : out STD_LOGIC_VECTOR(6 downto 0);
ANODE : inout STD_LOGIC_VECTOR(3 downto 0);
switches : in STD_LOGIC_VECTOR (1 downto 0);
pin_switch : out STD_LOGIC_VECTOR (1 downto 0);
botones : in STD_LOGIC_VECTOR (1 downto 0);
pin_boton : out STD_LOGIC_VECTOR (1 downto 0);
pin_boton_entradas : in STD_LOGIC_VECTOR (1 downto 0);
clock:in STD_LOGIC);
end sec;

architecture Behavioral of sec is

signal clkdiv : STD_LOGIC_VECTOR (12 downto 0);
signal clk2 : STD_LOGIC;
signal contador : STD_LOGIC_VECTOR(1 downto 0);

begin

process(clk2)
begin
if(rising_edge(clk2)) then
contador <= contador + 1;
end if;

case contador is
when "00" =>

if botones = "00" then
pin_boton(0) <= botones(0);
pin_boton(1) <= botones(1);
end if;

if botones = "01" then
pin_boton(0) <= botones(0);
pin_boton(1) <= botones(1);
end if;

if botones = "10" then
pin_boton(0) <= botones(0);
pin_boton(1) <= botones(1);
end if;

if botones = "11" then
pin_boton(0) <= botones(0);
pin_boton(1) <= botones(1);
end if;



if pin_boton_entradas = "00" then
ANODE <= "1110";
Display <= "0000110";
end if;

if pin_boton_entradas = "01" then
ANODE <= "1110";
Display <= "1001110";
end if;

if pin_boton_entradas = "10" then
ANODE <= "1110";
Display <= "0001000";
end if;

if pin_boton_entradas = "11" then
ANODE <= "1110";
Display <= "0000110";
end if;




when "01" => ANODE <= "1101";
Display <= "0111111";
when "10" => ANODE <= "1011";
Display <= "0111111";




when "11" =>

if switches = "00" then
Display<= "0001100";
ANODE<= "0111";
pin_switch(0) <= switches(0);
pin_switch(1) <= switches(1);
end if;

if switches = "01" then
Display<= "0001110";
ANODE<= "0111";
pin_switch(0) <= switches(0);
pin_switch(1) <= switches(1);
end if;

if switches = "10" then
Display<= "0000011";
ANODE<= "0111";
pin_switch(0) <= switches(0);
pin_switch(1) <= switches(1);
end if;

if switches = "11" then
Display<= "0010000";
ANODE<= "0111";
pin_switch(0) <= switches(0);
pin_switch(1) <= switches(1);
end if;



when others => ANODE <= "1111";
Display <= "1000000";
end case;

end process;

process (clock)

begin

if(rising_edge(clock)) then

if clkdiv="0000000000000" then
clk2 <= '1';
else
clk2<= '0';
end if;

clkdiv<=clkdiv+"0000000000001";

if clkdiv > "0000000001000" then
clkdiv<="0000000000000";
end if;

end if;

end process;

end Behavioral;

Share