Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Library ieee;
- Use ieee.std_logic_1164.all;
- Use ieee.numeric_std.all;
- entity elevador IS
- PORT (ck,
- clk_button,
- rst_button, -- SW[0]
- rst_db, -- SW[1]
- botoes_andar_switch0, --SW[9]
- botoes_andar_switch1, --SW[8]
- botoes_andar_switch2, --SW[7]
- botoes_andar_switch3 --SW[6]
- : IN STD_LOGIC;
- ANDAR_REQUISITADO_LED, -- LED[9-6]
- ANDAR_ATUAL_LED -- LED[5-2]
- : OUT STD_LOGIC_VECTOR(3 DOWNTO 0);
- STATE_RESPONSE -- LED[1-0] -- diz se o elevador esta parado "00", subindo "01" ou descendo "11"
- : OUT STD_LOGIC_VECTOR(1 DOWNTO 0)
- );
- end elevador;
- ARCHITECTURE arch OF elevador IS
- COMPONENT debouncer
- PORT(
- clk, rst_n, inb : in STD_LOGIC;
- outb : OUT STD_LOGIC
- );
- END COMPONENT;
- TYPE st IS (parado, subindo, descendo);
- SIGNAL estado : st;
- SIGNAL out_clk_db,
- out_rst_db,
- botoes_andar0,
- botoes_andar1,
- botoes_andar2,
- botoes_andar3
- : STD_LOGIC;
- SIGNAL andar_atual, andar_requisitado : STD_LOGIC_VECTOR (3 downto 0);
- BEGIN
- D1 : debouncer PORT MAP(clk => ck, rst_n => rst_db, inb => clk_button, outb => out_clk_db);
- D2 : debouncer PORT MAP(clk => ck, rst_n => rst_db, inb => rst_button, outb => out_rst_db);
- D3 : debouncer PORT MAP(clk => ck, rst_n => rst_db, inb => botoes_andar_switch0, outb => botoes_andar0);
- D4 : debouncer PORT MAP(clk => ck, rst_n => rst_db, inb => botoes_andar_switch1, outb => botoes_andar1);
- D5 : debouncer PORT MAP(clk => ck, rst_n => rst_db, inb => botoes_andar_switch2, outb => botoes_andar2);
- D6 : debouncer PORT MAP(clk => ck, rst_n => rst_db, inb => botoes_andar_switch3, outb => botoes_andar3);
- PROCESS(out_clk_db, out_rst_db)
- BEGIN
- IF out_rst_db = '1' THEN
- estado <= parado;
- andar_atual <= "0000";
- ANDAR_ATUAL_LED <= "0000";
- ANDAR_REQUISITADO_LED <= "0000";
- STATE_RESPONSE <= "00";
- ELSIF rising_edge(out_clk_db) THEN
- CASE estado IS
- ------------------------------------------------------------------------------------
- WHEN parado =>
- STATE_RESPONSE <= "00";
- andar_requisitado <= "0000";
- IF (botoes_andar0 = '1') THEN
- andar_requisitado <= std_logic_vector(unsigned(andar_requisitado) + "0001");
- END IF;
- IF (botoes_andar1 = '1') THEN
- andar_requisitado <= std_logic_vector(unsigned(andar_requisitado) + "0010");
- END IF;
- IF (botoes_andar2 = '1') THEN
- andar_requisitado <= std_logic_vector(unsigned(andar_requisitado) + "0100");
- END IF;
- IF (botoes_andar3 = '1') THEN
- andar_requisitado <= std_logic_vector(unsigned(andar_requisitado) + "1000");
- END IF;
- ANDAR_REQUISITADO_LED <= andar_requisitado;
- IF (to_integer(unsigned(andar_requisitado)) > to_integer(unsigned(andar_atual))) THEN
- estado <= subindo;
- ELSIF (to_integer(unsigned(andar_requisitado)) < to_integer(unsigned(andar_atual))) THEN
- estado <= descendo;
- ELSE
- estado <= parado;
- END IF;
- ------------------------------------------------------------------------------------
- WHEN subindo =>
- STATE_RESPONSE <= "01";
- IF (to_integer(unsigned(andar_requisitado)) > to_integer(unsigned(andar_atual))) THEN
- andar_atual <= std_logic_vector(unsigned(andar_atual) + "0001");
- ANDAR_ATUAL_LED <= andar_atual;
- ELSE
- estado <= parado;
- END IF;
- ------------------------------------------------------------------------------------
- WHEN descendo =>
- STATE_RESPONSE <= "11";
- IF (to_integer(unsigned(andar_requisitado)) < to_integer(unsigned(andar_atual))) THEN
- andar_atual <= std_logic_vector(unsigned(andar_atual) - "0001");
- ANDAR_ATUAL_LED <= andar_atual;
- ELSE
- estado <= parado;
- END IF;
- ------------------------------------------------------------------------------------
- END CASE;
- END IF;
- END process;
- END arch;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement