% \title{Multiplexor dual 74VHC153}
\documentclass[x11names]{standalone} % La opción 'x11names' se usa para referirse a este modelo de color.
\usepackage{tikz, verbatim}
\usepackage[scaled]{uarial}
\renewcommand*\familydefault{\sfdefault}
\usepackage[T1]{fontenc}
\begin{comment}
Este esquema representa un circuito integrado de tecnología CMOS 74VHC153 que representa dos multiplexores con las siguientes características:
* Dos entradas de habilitación de cada mitad, denominadas E_a y E_b 
* Dos entradas de direccionamiento comunes S_a y S_b
* Dos salidas (1 por cada multiplexor)
* Cuatro entradas de datos (I_na e I_nb) por cada multiplexor
Este esquema ha sido tomado y adaptado de la hoja de especificaciones loclizada en http://www.fairchildsemi.com/datasheets/74/74VHC153.pdf
\end{comment}
\usetikzlibrary{circuits.logic.US} % Biblioteca TiKZ para Circuitos Lógicos según la norma estadounidense.
\begin{document}
\begin{tikzpicture}
	[circuit logic US, 
	every circuit symbol/.style={thick, point down}, % Estilo común de compuertas lógicas
	every and gate/.style={inputs={nnnn}}, % Estilo común de compuertas AND
	every or gate/.style={inputs={nnnn}} % Estilo común de compuertas OR
    ]
% Título del esquema
    \node[color=Blue1, font=\large] at (6.5,6) {74VHC153};
	% Compuertas lógicas en el lado izquierdo del Multiplexor
    \node[buffer gate,inputs={i}] (buf1) at (-1,3) {}; % Entrada de habilitación Ea
    \foreach \x in {1,...,4}{
	\pgfmathtruncatemacro{\y}{\x+4} % Esta operación permite calcular el desplazamiento en forma entera y asignarlo a un nombre de variable
    \draw
    node[and gate](and\x) at (1.5*\x-1.5,-1){} % Compuertas AND (Y) del lado izquierdo
	node[and gate](and\y) at (1.5*\x+6.5,-1){}; % Compuertas AND (Y) del lado derecho
    }
    \draw
    node[or gate] (or1) at (2.25,-3) {}
	node[not gate] (not1) at (5.5,4) {} % Entrada de direccionamiento Sa
	node[buffer gate,inputs={i}] (buf2) at (5.5,2.5) {};
	% Conexiones del lado izquierdo del esquema
	\draw [red, very thick] 
    (buf1.output) -- ++(down:26.3mm) -| 
    (and1.input 4);
    \draw
    (and1.output) -- ++(down:5mm) -| (or1.input 4)
	(and2.output) -- ++(down:3mm) -| (or1.input 3)
	(and3.output) -- ++(down:3mm) -| (or1.input 2)
	(and4.output) -- ++(down:5mm) -| (or1.input 1)
	(not1.output) -- (buf2.input)
	% Compuertas lógicas en el lado derecho del Multiplexor
	node[not gate] (not2) at (7,4) {} % Entrada de direccionamiento Sb
	node[buffer gate,inputs={i}] (buf3) at (7,2.5) {}
	node[buffer gate,inputs={i}] (buf4) at (13.50,3) {} % Entrada de habilitación Eb
	node[or gate] (or2) at (10.25,-3) {}
	(not2.output) -- (buf3.input);
	% Conexiones del lado derecho del esquema
	\draw [red, very thick] (buf4.output) -- ++(down:26.3mm) -| (and8.input 1);
	\draw 
    (and5.output) -- ++(down:5mm) -| (or2.input 4)
	(and6.output) -- ++(down:3mm) -| (or2.input 3)
	(and7.output) -- ++(down:3mm) -| (or2.input 2)
	(and8.output) -- ++(down:5mm) -| (or2.input 1)
	% Entradas y Salidas del Multiplexor
	(buf1.input) -- ++(up:5mm) node [above]{$\bar{E}_a$} % Línea de habilitación Ea
	(buf4.input) -- ++(up:5mm) node [above]{$\bar{E}_b$} % Línea de habilitación Eb
	(not1.input) -- ++(up:5mm) node [above]{$S_a$} % Señal de selección Sa
	(not2.input) -- ++(up:5mm) node [above]{$S_b$}; % Señal de selección Sb
 	% Entradas I_na con n={0, 1, 2, 3}
	\draw [very thick] 
    (and1.input 1) -- ++(up:4.3) node [above]{$I_{0a}$}
	(and2.input 1) -- ++(up:4.3) node [above]{$I_{1a}$}
	(and3.input 1) -- ++(up:4.3) node [above]{$I_{2a}$}
	(and4.input 1) -- ++(up:4.3) node [above]{$I_{3a}$}
	% Entradas I_nb con n={0, 1, 2, 3}
	(and5.input 4) -- ++(up:4.3) node [above]{$I_{0b}$}
	(and6.input 4) -- ++(up:4.3) node [above]{$I_{1b}$}
	(and7.input 4) -- ++(up:4.3) node [above]{$I_{2b}$}
	(and8.input 4) -- ++(up:4.3) node [above]{$I_{3b}$};
	% Salida de las compuertas NOT (NO)
	\draw [Blue1, very thick] 
    (not1.output) -- ++(down:2.5mm) -| (6,0.45)
	(not1.output) to (buf2.input);
	\draw [Gold3, very thick] 
    (not2.output) -- ++(down:2.5mm) -| (6.5,0.1) 
    (not2.output) to (buf3.input);
	% Salida de las compuertas BUFFER
	\draw [Brown4, very thick] (buf2.output) -- (5.5,1);
	\draw [Green4, very thick] (buf3.output) -- (7,0.7);
	% Interconexión de compuertas AND (Y)
	\draw [red,very thick] 
    (and1.input 4) -- ++(up:3mm) -| 
    (and2.input 4) -- ++(up:3mm) -| 
    (and3.input 4) -- ++(up:3mm) -| 
    (and4.input 4)
	(and5.input 1) -- ++(up:3mm) -| 
    (and6.input 1) -- ++(up:3mm) -| 
    (and7.input 1) -- ++(up:3mm) -| 
    (and8.input 1);
	\draw [Blue1,very thick] 
    (and1.input 3) -- ++(up:9mm) -| 
    (and2.input 3) -- ++(up:9mm) -| 
    (and5.input 3) -- ++(up:9mm) -| 
    (and6.input 3);
	\draw [Gold3,very thick] 
    (and1.input 2) -- ++(up:6mm) -| 
    (and3.input 2) -- ++(up:6mm) -| 
    (and5.input 2) -- ++(up:6mm) -| 
    (and7.input 2);
	\draw [Green4,very thick] 
    (and2.input 2) -- ++(up:12mm) -| 
    (and4.input 2) -- ++(up:12mm) -| 
    (and6.input 2) -- ++(up:12mm) -| 
    (and8.input 2);
	\draw [Brown4,very thick] 
    (and3.input 3) -- ++(up:15mm) -| 
    (and4.input 3) -- ++(up:15mm) -| 
    (and7.input 3) -- ++(up:15mm) -| 
    (and8.input 3);
    % Salidas de los multiplexores
    \draw 
    (or1.output) -- ++(down:5mm) node [below]{$Z_a$}
    (or2.output) -- ++(down:5mm) node [below]{$Z_b$};
\end{tikzpicture}
\end{document}