我在电路中使用 MCP23017 GPIO 扩展器,现在我想使用 Circuitikz 绘制电路图。我对 Latex 还不太熟悉,我搜索了好多地方,但似乎找不到任何示例。有人知道如何在 Circuitikz 中表示这个芯片吗?
该芯片的数据表是:http://ww1.microchip.com/downloads/en/DeviceDoc/21952b.pdf
答案1
这是28脚DIP封装。您可以使用参数调整尺寸pin spacing
。
\documentclass[border=1pt]{standalone}
\usepackage{circuitikz}
\makeatletter
% ************************** multipoles *****************************
\ctikzset{multipoles/.is family}
\ctikzset{multipoles/pin spacing/.initial = 5mm} % default value
\ctikzset{multipoles/gate spacing/.initial = 1cm} % default value
\pgfkeys{/tikz/pin spacing/.initial = 0mm}
\pgfkeys{/tikz/pin spacing/.default = 0mm}
\newlength{\IClen} % scale factor
\newcommand{\pinsize}{\ifdim\IClen<3.5mm \tiny \else \scriptsize \fi}
\newcommand{\Compass}% define anchors for compass points
{\anchor{north east}{\northeast}
\anchor{south west}{\southwest}
\anchor{north}{\pgfextracty{\pgf@circ@res@up}{\northeast}\pgfpoint{0cm}{\pgf@circ@res@up}}
\anchor{north west}{\pgfextracty{\pgf@circ@res@up}{\northeast}\pgfextractx{\pgf@circ@res@left}{\southwest}\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@up}}
\anchor{west}{\pgfextractx{\pgf@circ@res@left}{\sosuthwest}\pgfpoint{\pgf@circ@res@left}{0cm}}
\anchor{south}{\pgfextracty{\pgf@circ@res@down}{\southwest}\pgfpoint{0cm}{\pgf@circ@res@down}}
\anchor{south east}{\pgfextracty{\pgf@circ@res@down}{\southwest}\pgfextractx{\pgf@circ@res@right}{\northeast}\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@down}}
\anchor{east}{\pgfextractx{\pgf@circ@res@right}{\northeast}\pgfpoint{\pgf@circ@res@right}{0cm}}}
% ***************************** dip 28 *********************************
\pgfdeclareshape{dip28}{
\anchor{center}{\pgfpointorigin} % within the node, (0,0) is the center
\anchor{text} % this is used to center the text in the node
{\pgfpoint{-.5\wd\pgfnodeparttextbox}{-.5\ht\pgfnodeparttextbox}}
\savedmacro{\resize}{ % called automatically
\setlength{\IClen}{\pgfkeysvalueof{/tikz/pin spacing}} % from node[]
\ifdim\IClen=0mm \setlength{\IClen}
{\pgfkeysvalueof{/tikz/circuitikz/multipoles/pin spacing}} \fi % from \ctikzset{}
}
\savedanchor\icpina{\pgfpoint{-6.5\IClen}{-2.5\IClen}} % pin 1
\anchor{p1}{\icpina}
\savedanchor\icpinb{\pgfpoint{-5.5\IClen}{-2.5\IClen}} % pin 2
\anchor{p2}{\icpinb}
\savedanchor\icpinc{\pgfpoint{-4.5\IClen}{-2.5\IClen}} % pin 3
\anchor{p3}{\icpinc}
\savedanchor\icpind{\pgfpoint{-3.5\IClen}{-2.5\IClen}} % pin 4
\anchor{p4}{\icpind}
\savedanchor\icpine{\pgfpoint{-2.5\IClen}{-2.5\IClen}} % pin 5
\anchor{p5}{\icpine}
\savedanchor\icpinf{\pgfpoint{-1.5\IClen}{-2.5\IClen}} % pin 6
\anchor{p6}{\icpinf}
\savedanchor\icping{\pgfpoint{-.5\IClen}{-2.5\IClen}} % pin 7
\anchor{p7}{\icping}
\savedanchor\icpinh{\pgfpoint{.5\IClen}{-2.5\IClen}} % pin 8
\anchor{p8}{\icpinh}
\savedanchor\icpini{\pgfpoint{1.5\IClen}{-2.5\IClen}} % pin 9
\anchor{p9}{\icpini}
\savedanchor\icpinj{\pgfpoint{2.5\IClen}{-2.5\IClen}} % pin 10
\anchor{p10}{\icpinj}
\savedanchor\icpink{\pgfpoint{3.5\IClen}{-2.5\IClen}} % pin 11
\anchor{p11}{\icpink}
\savedanchor\icpinl{\pgfpoint{4.5\IClen}{-2.5\IClen}} % pin 12
\anchor{p12}{\icpinl}
\savedanchor\icpinm{\pgfpoint{5.5\IClen}{-2.5\IClen}} % pin 13
\anchor{p13}{\icpinm}
\savedanchor\icpinn{\pgfpoint{6.5\IClen}{-2.5\IClen}} % pin 14
\anchor{p14}{\icpinn}
\savedanchor\icpino{\pgfpoint{6.5\IClen}{2.5\IClen}} % pin 15
\anchor{p15}{\icpino}
\savedanchor\icpinp{\pgfpoint{5.5\IClen}{2.5\IClen}} % pin 16
\anchor{p16}{\icpinp}
\savedanchor\icpinq{\pgfpoint{4.5\IClen}{2.5\IClen}} % pin 17
\anchor{p17}{\icpinq}
\savedanchor\icpinr{\pgfpoint{3.5\IClen}{2.5\IClen}} % pin 18
\anchor{p18}{\icpinr}
\savedanchor\icpins{\pgfpoint{2.5\IClen}{2.5\IClen}} % pin 19
\anchor{p19}{\icpins}
\savedanchor\icpint{\pgfpoint{1.5\IClen}{2.5\IClen}} % pin 20
\anchor{p20}{\icpint}
\savedanchor\icpinu{\pgfpoint{.5\IClen}{2.5\IClen}} % pin 21
\anchor{p21}{\icpinu}
\savedanchor\icpinv{\pgfpoint{-.5\IClen}{2.5\IClen}} % pin 22
\anchor{p22}{\icpinv}
\savedanchor\icpinw{\pgfpoint{-1.5\IClen}{2.5\IClen}} % pin 23
\anchor{p23}{\icpinw}
\savedanchor\icpinx{\pgfpoint{-2.5\IClen}{2.5\IClen}} % pin 24
\anchor{p24}{\icpinx}
\savedanchor\icpiny{\pgfpoint{-3.5\IClen}{2.5\IClen}} % pin 25
\anchor{p25}{\icpiny}
\savedanchor\icpinz{\pgfpoint{-4.5\IClen}{2.5\IClen}} % pin 26
\anchor{p26}{\icpinz}
\savedanchor\icpinaa{\pgfpoint{-5.5\IClen}{2.5\IClen}} % pin 27
\anchor{p27}{\icpinaa}
\savedanchor\icpinab{\pgfpoint{-6.5\IClen}{2.5\IClen}} % pin 28
\anchor{p28}{\icpinab}
\savedanchor{\northeast}{\pgfpoint{7\IClen}{2.5\IClen}}
\savedanchor{\southwest}{\pgfpoint{-7\IClen}{-2.5\IClen}}
\Compass% standard anchors
\foregroundpath{ % border and pin numbers are drawn here
\pgfsetlinewidth{.1\IClen} % line thickness
\pgfpathrectanglecorners{\southwest}{\northeast}
\pgfusepath{draw} %draw rectangle
\pgfsetlinewidth{.06\IClen} % line thickness
\pgfpathmoveto{\pgfpoint{-7\IClen}{-.6\IClen}}
\pgfpatharc{-90}{90}{.6\IClen}
\pgfusepath{draw} %draw semicircle
\pgftext[bottom,at={\pgfpoint{-6.5\IClen}{-2.2\IClen}}]{\pinsize 1}
\pgftext[bottom,at={\pgfpoint{-5.5\IClen}{-2.2\IClen}}]{\pinsize 2}
\pgftext[bottom,at={\pgfpoint{-4.5\IClen}{-2.2\IClen}}]{\pinsize 3}
\pgftext[bottom,at={\pgfpoint{-3.5\IClen}{-2.2\IClen}}]{\pinsize 4}
\pgftext[bottom,at={\pgfpoint{-2.5\IClen}{-2.2\IClen}}]{\pinsize 5}
\pgftext[bottom,at={\pgfpoint{-1.5\IClen}{-2.2\IClen}}]{\pinsize 6}
\pgftext[bottom,at={\pgfpoint{-.5\IClen}{-2.2\IClen}}]{\pinsize 7}
\pgftext[bottom,at={\pgfpoint{.5\IClen}{-2.2\IClen}}]{\pinsize 8}
\pgftext[bottom,at={\pgfpoint{1.5\IClen}{-2.2\IClen}}]{\pinsize 9}
\pgftext[bottom,at={\pgfpoint{2.5\IClen}{-2.2\IClen}}]{\pinsize 10}
\pgftext[bottom,at={\pgfpoint{3.5\IClen}{-2.2\IClen}}]{\pinsize 11}
\pgftext[bottom,at={\pgfpoint{4.5\IClen}{-2.2\IClen}}]{\pinsize 12}
\pgftext[bottom,at={\pgfpoint{5.5\IClen}{-2.2\IClen}}]{\pinsize 13}
\pgftext[bottom,at={\pgfpoint{6.5\IClen}{-2.2\IClen}}]{\pinsize 14}
\pgftext[top,at={\pgfpoint{6.5\IClen}{2.2\IClen}}]{\pinsize 15}
\pgftext[top,at={\pgfpoint{5.5\IClen}{2.2\IClen}}]{\pinsize 16}
\pgftext[top,at={\pgfpoint{4.5\IClen}{2.2\IClen}}]{\pinsize 17}
\pgftext[top,at={\pgfpoint{3.5\IClen}{2.2\IClen}}]{\pinsize 18}
\pgftext[top,at={\pgfpoint{2.5\IClen}{2.2\IClen}}]{\pinsize 19}
\pgftext[top,at={\pgfpoint{1.5\IClen}{2.2\IClen}}]{\pinsize 20}
\pgftext[top,at={\pgfpoint{.5\IClen}{2.2\IClen}}]{\pinsize 21}
\pgftext[top,at={\pgfpoint{-.5\IClen}{2.2\IClen}}]{\pinsize 22}
\pgftext[top,at={\pgfpoint{-1.5\IClen}{2.2\IClen}}]{\pinsize 23}
\pgftext[top,at={\pgfpoint{-2.5\IClen}{2.2\IClen}}]{\pinsize 24}
\pgftext[top,at={\pgfpoint{-3.5\IClen}{2.2\IClen}}]{\pinsize 25}
\pgftext[top,at={\pgfpoint{-4.5\IClen}{2.2\IClen}}]{\pinsize 26}
\pgftext[top,at={\pgfpoint{-5.5\IClen}{2.2\IClen}}]{\pinsize 27}
\pgftext[top,at={\pgfpoint{-6.5\IClen}{2.2\IClen}}]{\pinsize 28}
}}
\makeatother
\begin{document}
\begin{circuitikz}
\draw (2,3.5) node[dip28] (Q) {MCP23017};
\draw
(Q.p1) -- +(0,-.5)
(Q.p2) -- +(0,-.5)
(Q.p3) -- +(0,-.5)
(Q.p4) -- +(0,-.5)
(Q.p5) -- +(0,-.5)
(Q.p6) -- +(0,-.5)
(Q.p7) -- +(0,-.5)
(Q.p8) -- +(0,-.5)
(Q.p9) -- +(0,-.5)
(Q.p10) -- +(0,-.5)
(Q.p11) -- +(0,-.5)
(Q.p12) -- +(0,-.5)
(Q.p13) -- +(0,-.5)
(Q.p14) -- +(0,-.5)
(Q.p15) -- +(0,.5)
(Q.p16) -- +(0,.5)
(Q.p17) -- +(0,.5)
(Q.p18) -- +(0,.5)
(Q.p19) -- +(0,.5)
(Q.p20) -- +(0,.5)
(Q.p21) -- +(0,.5)
(Q.p22) -- +(0,.5)
(Q.p23) -- +(0,.5)
(Q.p24) -- +(0,.5)
(Q.p25) -- +(0,.5)
(Q.p26) -- +(0,.5)
(Q.p27) -- +(0,.5)
(Q.p28) -- +(0,.5);
\end{circuitikz}
\end{document}