Altera_Forum
Honored Contributor
13 years agoA little problem how "open and close and locked door"
library ieee;
use ieee.std_logic_1164.all; entity uppgift4a_more_2 is port ( -- Insignaler CLOCK, reset_n : IN std_logic; KEY_0, KEY_1 : IN std_logic; -- Utsignaler LEDG_0, LEDG_1,LEDR_0,LEDR_1, led : OUT std_logic); end entity; architecture rtl of uppgift4a_more_2 is -- Build an enumerated type for the state machine type state_type is (opening_1,closing_2, open, close); -- Register to hold the current state signal state : state_type; begin process (reset_n, CLOCK) begin if reset_n = '0' then state <= opening_1; elsif (rising_edge(CLOCK)) then case state is when closing_2=> if KEY_0 = '1' then state <= close; else state <= closing_2; end if; when close => state <= closing_2; when open => state <= opening_1; when opening_1 => if KEY_1 = '1' then state <= open; else state <= opening_1; end if; when others => state <= opening_1; end case; end if; end process; process (state) begin case state is when closing_2=> led <= '1';LEDG_0 <= '0'; LEDG_1 <= '0'; when open => LEDG_0 <= '1'; LEDG_1 <= '0'; led <= '1'; when close => LEDG_1 <= '1'; LEDG_0 <= '0'; led <= '0'; when opening_1 => led <= '0'; LEDG_0 <= '0'; LEDG_1 <= '0'; when others => LED_1 <= '0';LEDR_0 <= '0'; led <= '0'; when opening_1 => led <= '0'; LEDR_0 <= '0'; LEDR_1 <= '0'; when others => LEDG_1 <= '0';LEDR_0 <= '0'; led <= '0'; end case; end case; end process; i vonder what is wrong with this code :unsure: end;