---------------------------------------------------------------------------------- -- Company: -- Engineer: -- -- Create Date: 17:29:58 12/15/2008 -- Design Name: -- Module Name: ampel - Behavioral -- Project Name: -- Target Devices: -- Tool versions: -- Description: -- -- Dependencies: -- -- Revision: -- Revision 0.01 - File Created -- Additional Comments: -- ---------------------------------------------------------------------------------- library IEEE; use IEEE.STD_LOGIC_1164.ALL; use IEEE.STD_LOGIC_ARITH.ALL; use IEEE.STD_LOGIC_UNSIGNED.ALL; ---- Uncomment the following library declaration if instantiating ---- any Xilinx primitives in this code. --library UNISIM; --use UNISIM.VComponents.all; entity boardtest is Port ( clk : in std_logic; led_ampel : out std_logic_vector(5 downto 0); led_schloss: out std_logic_vector(4 downto 0); switch: in std_logic; btn : in std_logic_vector(3 downto 0)); end boardtest; architecture Behavioral of boardtest is signal clkdiv: std_logic_vector(30 downto 0); signal status: std_logic_vector(5 downto 0); -- <= "001100"; signal clk2: std_logic; signal clk3: std_logic; signal pressed: std_logic; signal led_out: std_logic_vector(4 downto 0); begin process(clk) begin if clk='1' and clk'event then clkdiv <= clkdiv+1; end if; end process; clk2 <= clkdiv(25); -- Taktteiler für "Schaltgeschwindigkeit" der Ampel clk3 <= clkdiv(20); ampel: process(clk2, switch) variable state: integer range 0 to 6:=0; variable count_pkw_red: integer range 0 to 3:=0; variable count_pkw_green: integer range 0 to 4:=0; variable count_fg_green: integer range 0 to 4:=0; begin if clk2='1' and clk2'event and switch='1' then case state is when 0 => status <= "001100"; if btn(0)='1' or pressed='1' then pressed <='0'; state := 1; else state := 0; end if; when 1 => status <= "001010"; state := 2; when 2 => status <= "001001"; if count_pkw_red = 2 then count_pkw_red:=0; state:=3; else count_pkw_red := count_pkw_red+1; state:=2; end if; when 3 => status <= "010001"; if count_fg_green = 4 then count_fg_green := 0; state:=4; else count_fg_green := count_fg_green+1; state:=3; end if; when 4 => status <= "001001"; if btn(0)='1' then pressed <= '1'; end if; if count_pkw_red = 3 then count_pkw_red := 0; state:=5; else count_pkw_red := count_pkw_red+1; state:=4; end if; when 5 => status <= "001011"; if btn(0)='1' then pressed <= '1'; end if; state:=6; when 6 => status <= "001100"; if btn(0)='1' then pressed <= '1'; end if; if count_pkw_green = 4 then count_pkw_green := 0; state := 0; else count_pkw_green := count_pkw_green+1; state := 6; end if; when others => state := 0; end case; end if; end process ampel; led_ampel <= status; schloss: process(clk3, switch) variable state: integer range 0 to 8:=0; begin if clk3='1' and clk3'event and switch='0' then case state is when 0 => led_out <="00000"; if btn(3) = '1' then led_out <= "10000"; state:=1; elsif (btn(2) or btn(1) or btn(0)) ='1' then state:=7; elsif (btn(3) and btn(0)) ='1' then state:=8; else state:=0; end if; when 1 => if btn(3) = '0' then state:=2; else state:=1; end if; when 2 => if btn(2) = '1' then led_out <= "11000"; state:=3; elsif (btn(3) or btn(1) or btn(0)) ='1' then state:=7; elsif (btn(3) and btn(0)) ='1' then state:=8; else state:=2; end if; when 3 => if btn(2) = '0' then state:=4; else state:=3; end if; when 4 => if btn(1) = '1' then led_out <= "11100"; state:=5; elsif (btn(3) or btn(2) or btn(0)) ='1' then state:=7; elsif (btn(3) and btn(0)) ='1' then state:=8; else state:=4; end if; when 5 => if btn(1) = '0' then state:=6; else state:=5; end if; when 6 => if btn(0) = '1' then led_out <= "11110"; state:=6; elsif (btn(3) or btn(2) or btn(1)) ='1' then state:=7; elsif (btn(3) and btn(0)) ='1' then state:=8; else state:=6; end if; when 7 => led_out <= "00001"; if (btn(3) and btn(0)) ='1' then state:=8; else state:=7; end if; when 8 => if (btn(0) and btn(3)) = '0' then state:=0; else state:=8; end if; when others => state :=0; end case; end if; led_schloss <= led_out; end process schloss; end Behavioral;