1

I would like to create logic symbols with custom number of outputs circuits library in TikZ. Half adder can be an example of such symbol, and I want to use its outputs as easy as inputs (e.g., .output 1).

half adder element

Moreover, I want its outputs to look the same as inputs (to be at the same horizontal positions and so on). Are there any ways to do such things? Maybe, there are some ways to create a key logic gate outputs to use it like logic gate outputs=nn likewise the inputs?

Tim
  • 11

1 Answers1

1

enter image description here

\documentclass[border={10pt}]{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning}
\usepackage[siunitx,european,american]{circuitikz}
\usetikzlibrary{circuits.logic.US,circuits.logic.IEC,calc}
\begin{document}
\begin{tikzpicture}
    [%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
        block/.style={fill=blue!20,draw=red!70,thick,minimum width=1cm,minimum height=1.5cm}
    ]%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\draw (0,0)
  node[block, label={[label distance=-3ex]90:{\scriptsize HSUM}}] (P) {} 
  ($(P.north west)!0.4!(P.south west)$) coordinate (Pin 1)
  ($(P.north west)!0.6!(P.south west)$) coordinate (Pin 2)
  ($(P.north east)!0.4!(P.south east)$) coordinate (Pout 1)
  ($(P.north east)!0.6!(P.south east)$) coordinate (Pout 2)
  (Pin 1) to[short,-o] ++(-0.5, 0) coordinate (input1) node[left] {\tiny p1}
  (Pin 2) to[short,-o] ++(-0.5, 0) coordinate (input2) node[left] {\tiny p2}
  (Pout 1) to[short,-o] ++(0.5, 0) coordinate (output1) node[right] {\tiny p3}
  (Pout 2) to[short,-o] ++(0.5, 0) coordinate (output2) node[right] {\tiny p4}
;

\end{tikzpicture} \end{document}

OR

as described by @Rmano here -- https://tex.stackexchange.com/a/596334/197451

\documentclass[border=10pt]{standalone}
\usepackage[siunitx, RPvoltages]{circuitikz}
\begin{document}
\begin{tikzpicture}[]
    \tikzset{ic555/.style={muxdemux,
            muxdemux def={Lh=10, NL=5, Rh=10, NR=5,
            NB=2, w=6, NT=2, square pins=1},
        no input leads, external pins width=0.4,
        circuitikz/muxdemuxes/fill=blue!10}
    }
    \node [ic555, font=\small\ttfamily,align=center](A) at (0,0) {HSUM};
    % left pins
    \foreach \rawpin/\npin/\label in {2/1/Input1, 4/2/Input2} {
        \draw (A.lpin \rawpin) -- (A.blpin \rawpin)
            node[midway, blue, font=\tiny, above]{\npin}
            node[right, font=\tiny]{\label};
    }
    % top pins
    % \foreach \rawpin/\npin in {1/8, 2/4} {
    %     \draw (A.tpin \rawpin) -- (A.btpin \rawpin)
    %         node[midway, blue, font=\small, left]{\npin};
    % }
    % bottom pins
    % \foreach \rawpin/\npin in {1/5, 2/1} {
    %     \draw (A.bpin \rawpin) -- (A.bbpin \rawpin)
    %         node[midway, blue, font=\small, left]{\npin};
    % }
    % finally, left
    \foreach \rawpin/\npin/\label in {2/3/Output1, 4/4/Output2} {
        \draw (A.rpin \rawpin) -- (A.brpin \rawpin)
            node[midway, blue, font=\tiny, above]{\npin}
            node[left, font=\tiny]{\label};
    }
    % \draw (A.rpin 3) -- (A.brpin 3) node[midway, blue, font=\small, above]{3};
\end{tikzpicture}
\end{document}

enter image description here

js bibra
  • 21,280