-- Library Clause LIBRARY ieee; f <= -- Use Clause USE ieee.std_logic_1164.ALL; a b (OTHERS => 'Z') WHEN "00", WHEN "01", WHEN OTHERS; END BLOCK pmux; END c; -- Entity Declaration ENTITY mux IS GENERIC(ancho : integer := 8); PORT( a : IN STD_LOGIC_VECTOR(ancho-1 downto 0); b : IN STD_LOGIC_VECTOR(ancho-1 downto 0); sel : IN STD_LOGIC; oe : IN STD_LOGIC; f : OUT STD_LOGIC_VECTOR(ancho-1 downto 0) ); END mux; -- Architecture Body********************************************* WHEN -- Architecture Body********************************************** IF ARCHITECTURE d OF mux IS SIGNAL dir : STD_LOGIC_VECTOR(1 DOWNTO 0); BEGIN PROCESS (sel,oe) BEGIN dir <= oe & sel; IF dir = "00" THEN f <= a; ELSIF dir = "01" THEN f <= b; ELSE f <= (OTHERS => 'Z'); END IF; END PROCESS; / ELSE ARCHITECTURE a OF mux IS SIGNAL dir : STD_LOGIC_VECTOR(1 DOWNTO 0); BEGIN dir <= oe & sel; f <= a b (OTHERS => 'Z'); WHEN dir = "00" ELSE WHEN dir = "01" ELSE END d; -- Architecture Body********************************************** CASE END a; -- Architecture Body********************************************** SELECT ARCHITECTURE e OF mux IS SIGNAL dir : STD_LOGIC_VECTOR(1 DOWNTO 0); ARCHITECTURE b OF mux IS BEGIN SIGNAL dir : STD_LOGIC_VECTOR(1 DOWNTO 0); PROCESS (sel,oe) BEGIN dir <= oe & sel; BEGIN dir <= oe & sel; WITH dir SELECT f <= a b (OTHERS => 'Z') WHEN "00", WHEN "01", WHEN OTHERS; ARCHITECTURE c OF mux IS CASE dir IS WHEN "00" => f <= a; WHEN "01" => f <= b; WHEN OTHERS => f <= (OTHERS => 'Z'); END CASE; SIGNAL dir : STD_LOGIC_VECTOR(1 DOWNTO 0); END PROCESS; END b; -- Architecture Body********************************************** BLOCK BEGIN END e; pmux: BLOCK BEGIN dir <= oe & sel; OPERADORES Lógicos: Relacionales: WITH dir SELECT /ELSIF / ELSE AND, NAND, OR, NOR, XOR, NOT >, >=, <, <=, =, /= / WHEN **************************************************************** ENTITY comp IS PORT(a,b: IN bit_vector(10 DOWNTO 0); amayb,aeqb,amenb: OUT bit); END comp; ARCHITECTURE flujo OF comp IS BEGIN amayb<='1' WHEN a>b ELSE '0'; aeqb <='1' WHEN a=b ELSE '0'; amenb<='1' WHEN a<b ELSE '0'; END flujo; **************************************************************** ENTITY shifter IS PORT( shftin: IN bit_vector(0 TO 3); shftout: OUT bit_vector(0 TO 3); shftctl: IN bit_vector(0 TO 1)); END shifter; ARCHITECTURE flujo1 OF shifter IS BEGIN shftout<=shftin WHEN shftctl="00" ELSE shftin(1 TO 3)&'0' WHEN shftctl="01" ELSE '0'&shftin(0 TO 2) WHEN shftctl="10" ELSE shftin(3)&shftin(0 TO 2); END flujo1; ARCHITECTURE flujo2 OF shifter IS BEGIN WITH shftctl SELECT shftout<=shftin WHEN "00", shftin(1 TO 3)&'0' WHEN "01", '0'&shftin(0 TO 2) WHEN "10", shftin(3)&shftin(0 TO 2) WHEN "11"; END flujo2; **************************************************************** ENTITY demux IS PORT(a: IN bit; sel: IN bit_vector(2 DOWNTO 0); sal: OUT bit_vector(0 TO 7)); END demux; ARCHITECTURE flujo OF demux IS SIGNAL aux: bit_vector(0 TO 3); BEGIN WITH sel SELECT aux<="0001" WHEN "00", "0010" WHEN "01", "0100" WHEN "10", "1000" WHEN "11"; sal<=aux AND a&a&a&a; END flujo; ARCHITECTURE otro_flujo OF demux IS BEGIN WITH sel SELECT sal<="000"&a WHEN "00", "00"&a&"0" WHEN "01", "0"&a&"00" WHEN "10", a&"000" WHEN "11"; END otro_flujo; ENTITY ascensor IS PORT(boton: IN bit_vector(0 TO 3); piso: IN bit_vector(1 DOWNTO 0); clk,reset,celula: IN bit; motor: OUT bit_vector(0 TO 1); puerta: OUT bit); END ascensor; ARCHITECTURE mover OF ascensor IS TYPE estado IS (inicial,cerrar,voy); SIGNAL presente: estado:=inicial; SIGNAL bot: bit_vector(1 DOWNTO 0); -- Almacena el botón pulsado FUNCTION codifica(pulso: bit_vector(0 TO 3)) RETURN bit_vector IS BEGIN CASE pulso IS WHEN "0001"=>RETURN "00"; WHEN "0010"=>RETURN "01"; WHEN "0100"=>RETURN "10"; WHEN "1000"=>RETURN "11"; WHEN OTHERS=>RETURN "00"; END CASE; END codifica; BEGIN fsm: PROCESS(reset,clk) BEGIN IF reset='1' THEN presente<=inicial; ELSIF clk='1' AND clk'event THEN CASE presente IS WHEN inicial=> IF boton/="0000" AND bot/=piso THEN presente<=cerrar; END IF; WHEN cerrar=> IF celula='0' THEN presente<=voy; -- Sin obstáculos END IF; WHEN voy=> IF bot=piso THEN presente<=inicial; END IF; END CASE; END IF; END PROCESS fsm; salida: PROCESS(presente,boton) BEGIN CASE presente IS WHEN inicial=> motor<="00"; -- Parado puerta<='1'; -- Abierta bot<=codifica(boton); -- Captura el botón WHEN cerrar=> motor<="00"; puerta<='1'; WHEN voy=> puerta<='0'; -- Cerrada IF bot>piso THEN motor<="10"; -- Subir ELSE motor<="01"; -- Bajar END IF; END CASE; END PROCESS salida; END mover;