diff options
Diffstat (limited to 'dff.tex')
-rw-r--r-- | dff.tex | 560 |
1 files changed, 560 insertions, 0 deletions
@@ -0,0 +1,560 @@ +% DFF aus einem Beispiel von Texamples + +\makeatletter +% D Flipflop mit allen Anschlüssen +\pgfdeclareshape{ff}{ + % The 'minimum width' and 'minimum height' keys, not the content, determine + % the size + \savedanchor\northeast{% + \pgfmathsetlength\pgf@x{\pgfshapeminwidth}% + \pgfmathsetlength\pgf@y{\pgfshapeminheight}% + \pgf@x=0.5\pgf@x + \pgf@y=0.5\pgf@y + } + % This is redundant, but makes some things easier: + \savedanchor\southwest{% + \pgfmathsetlength\pgf@x{\pgfshapeminwidth}% + \pgfmathsetlength\pgf@y{\pgfshapeminheight}% + \pgf@x=-0.5\pgf@x + \pgf@y=-0.5\pgf@y + } + % Inherit from rectangle + \inheritanchorborder[from=rectangle] + + % Define same anchor a normal rectangle has + \anchor{center}{\pgfpointorigin} + \anchor{north}{\northeast \pgf@x=0pt} + \anchor{east}{\northeast \pgf@y=0pt} + \anchor{south}{\southwest \pgf@x=0pt} + \anchor{west}{\southwest \pgf@y=0pt} + \anchor{north east}{\northeast} + \anchor{north west}{\northeast \pgf@x=-\pgf@x} + \anchor{south west}{\southwest} + \anchor{south east}{\southwest \pgf@x=-\pgf@x} + \anchor{text}{ + \pgfpointorigin + \advance\pgf@x by -.5\wd\pgfnodeparttextbox% + \advance\pgf@y by -.5\ht\pgfnodeparttextbox% + \advance\pgf@y by +.5\dp\pgfnodeparttextbox% + } + + % Define anchors for signal ports + \anchor{D}{ + \pgf@process{\northeast}% + \pgf@x=-1\pgf@x% + \pgf@y=.5\pgf@y% + } + \anchor{CLK}{ + \pgf@process{\northeast}% + \pgf@x=-1\pgf@x% + \pgf@y=-.5\pgf@y% + } +% \anchor{CE}{ +% \pgf@process{\northeast}% +% \pgf@x=-1\pgf@x% +% \pgf@y=-0.33333\pgf@y% +% } + \anchor{Q}{ + \pgf@process{\northeast}% + \pgf@y=.5\pgf@y% + } + \anchor{Qn}{ + \pgf@process{\northeast}% + \pgf@y=-.5\pgf@y% + } + \anchor{S}{ + \pgf@process{\northeast}% + \pgf@x=0pt% + } + \anchor{R}{ + \pgf@process{\northeast}% + \pgf@x=0pt% + \pgf@y=-\pgf@y% + \advance\pgf@y by -2mm% + } + % Draw the rectangle box and the port labels + \backgroundpath{ + % Rectangle box + \pgfpathrectanglecorners{\southwest}{\northeast} + % Angle (>) for clock input + \pgf@anchor@dff@CLK + \pgf@xa=\pgf@x \pgf@ya=\pgf@y + \pgf@xb=\pgf@x \pgf@yb=\pgf@y + \pgf@xc=\pgf@x \pgf@yc=\pgf@y + \pgfmathsetlength\pgf@x{1ex} % size depends on font size + \pgfmathsetlength\pgf@y{0.5ex} + \advance\pgf@ya by \pgf@y + \advance\pgf@xb by \pgf@x + \advance\pgf@yc by -\pgf@y + \pgfpathmoveto{\pgfpoint{\pgf@xa}{\pgf@ya}} + \pgfpathlineto{\pgfpoint{\pgf@xb}{\pgf@yb}} + \pgfpathlineto{\pgfpoint{\pgf@xc}{\pgf@yc}} + \pgfclosepath + + % Draw Reset Circle + \pgf@anchor@ff@R + \pgfcircle{\pgfrelative{\pgfpoint{\pgf@x}{\pgf@y}}{\pgfpoint{0}{+1mm}}}{1mm} + + % Draw port labels + \begingroup + \tikzset{flip flop/port labels} % Use font from this style + \tikz@textfont + + \pgf@anchor@ff@D + \pgftext[left,base,at={\pgfpoint{\pgf@x}{\pgf@y}},x=\pgfshapeinnerxsep]{\raisebox{-0.75ex}{D}} + +% \pgf@anchor@dff@CE + % \pgftext[left,base,at={\pgfpoint{\pgf@x}{\pgf@y}},x=\pgfshapeinnerxsep]{\raisebox{-0.75ex}{CE}} + + \pgf@anchor@ff@Q + \pgftext[right,base,at={\pgfpoint{\pgf@x}{\pgf@y}},x=-\pgfshapeinnerxsep]{\raisebox{-.75ex}{Q}} + + \pgf@anchor@ff@Qn + \pgftext[right,base,at={\pgfpoint{\pgf@x}{\pgf@y}},x=-\pgfshapeinnerxsep]{\raisebox{-.75ex}{$\overline{\mbox{Q}}$}} + + \pgf@anchor@ff@R + \pgftext[bottom,at={\pgfrelative{\pgfpoint{\pgf@x}{\pgf@y}}{\pgfpoint{0}{+2mm}}},y=\pgfshapeinnerysep]{R} + +% \pgf@anchor@ff@S +% \pgftext[top,at={\pgfpoint{\pgf@x}{\pgf@y}},y=-\pgfshapeinnerysep]{S} + \endgroup + } +} + + + +% Data Flip Flip (DFF) shape +% Ist ein FF ohne S,R,Qn +\pgfdeclareshape{dff}{ + % The 'minimum width' and 'minimum height' keys, not the content, determine + % the size + \savedanchor\northeast{% + \pgfmathsetlength\pgf@x{\pgfshapeminwidth}% + \pgfmathsetlength\pgf@y{\pgfshapeminheight}% + \pgf@x=0.5\pgf@x + \pgf@y=0.5\pgf@y + } + % This is redundant, but makes some things easier: + \savedanchor\southwest{% + \pgfmathsetlength\pgf@x{\pgfshapeminwidth}% + \pgfmathsetlength\pgf@y{\pgfshapeminheight}% + \pgf@x=-0.5\pgf@x + \pgf@y=-0.5\pgf@y + } + % Inherit from rectangle + \inheritanchorborder[from=rectangle] + + % Define same anchor a normal rectangle has + \anchor{center}{\pgfpointorigin} + \anchor{north}{\northeast \pgf@x=0pt} + \anchor{east}{\northeast \pgf@y=0pt} + \anchor{south}{\southwest \pgf@x=0pt} + \anchor{west}{\southwest \pgf@y=0pt} + \anchor{north east}{\northeast} + \anchor{north west}{\northeast \pgf@x=-\pgf@x} + \anchor{south west}{\southwest} + \anchor{south east}{\southwest \pgf@x=-\pgf@x} + \anchor{text}{ + \pgfpointorigin + \advance\pgf@x by -.5\wd\pgfnodeparttextbox% + \advance\pgf@y by -.5\ht\pgfnodeparttextbox% + \advance\pgf@y by +.5\dp\pgfnodeparttextbox% + } + + % Define anchors for signal ports + \anchor{D}{ + \pgf@process{\northeast}% + \pgf@x=-1\pgf@x% + \pgf@y=.5\pgf@y% + } + \anchor{CLK}{ + \pgf@process{\northeast}% + \pgf@x=-1\pgf@x% + \pgf@y=-.5\pgf@y% + } +% \anchor{CE}{ +% \pgf@process{\northeast}% +% \pgf@x=-1\pgf@x% +% \pgf@y=-0.33333\pgf@y% +% } + \anchor{Q}{ + \pgf@process{\northeast}% + \pgf@y=.5\pgf@y% + } +% \anchor{Qn}{ +% \pgf@process{\northeast}% +% \pgf@y=-.5\pgf@y% +% } +% \anchor{R}{ +% \pgf@process{\northeast}% +% \pgf@x=0pt% +% } +% \anchor{S}{ +% \pgf@process{\northeast}% +% \pgf@x=0pt% +% \pgf@y=-\pgf@y% +% } + % Draw the rectangle box and the port labels + \backgroundpath{ + % Rectangle box + \pgfpathrectanglecorners{\southwest}{\northeast} + % Angle (>) for clock input + \pgf@anchor@dff@CLK + \pgf@xa=\pgf@x \pgf@ya=\pgf@y + \pgf@xb=\pgf@x \pgf@yb=\pgf@y + \pgf@xc=\pgf@x \pgf@yc=\pgf@y + \pgfmathsetlength\pgf@x{1ex} % size depends on font size + \pgfmathsetlength\pgf@y{0.5ex} + \advance\pgf@ya by \pgf@y + \advance\pgf@xb by \pgf@x + \advance\pgf@yc by -\pgf@y + \pgfpathmoveto{\pgfpoint{\pgf@xa}{\pgf@ya}} + \pgfpathlineto{\pgfpoint{\pgf@xb}{\pgf@yb}} + \pgfpathlineto{\pgfpoint{\pgf@xc}{\pgf@yc}} + \pgfclosepath + + % Draw port labels + \begingroup + \tikzset{flip flop/port labels} % Use font from this style + \tikz@textfont + + \pgf@anchor@dff@D + \pgftext[left,base,at={\pgfpoint{\pgf@x}{\pgf@y}},x=\pgfshapeinnerxsep]{\raisebox{-0.75ex}{D}} + +% \pgf@anchor@dff@CE + % \pgftext[left,base,at={\pgfpoint{\pgf@x}{\pgf@y}},x=\pgfshapeinnerxsep]{\raisebox{-0.75ex}{CE}} + + \pgf@anchor@dff@Q + \pgftext[right,base,at={\pgfpoint{\pgf@x}{\pgf@y}},x=-\pgfshapeinnerxsep]{\raisebox{-.75ex}{Q}} + +% \pgf@anchor@dff@Qn +% \pgftext[right,base,at={\pgfpoint{\pgf@x}{\pgf@y}},x=-\pgfshapeinnerxsep]{\raisebox{-.75ex}{$\overline{\mbox{Q}}$}} + +% \pgf@anchor@dff@R +% \pgftext[top,at={\pgfpoint{\pgf@x}{\pgf@y}},y=-\pgfshapeinnerysep]{R} + +% \pgf@anchor@dff@S +% \pgftext[bottom,at={\pgfpoint{\pgf@x}{\pgf@y}},y=\pgfshapeinnerysep]{S} + \endgroup + } +} + +% latch shape +% Ist ein FF ohne S,R und Clock anders dargestellt +\pgfdeclareshape{latch}{ + % The 'minimum width' and 'minimum height' keys, not the content, determine + % the size + \savedanchor\northeast{% + \pgfmathsetlength\pgf@x{\pgfshapeminwidth}% + \pgfmathsetlength\pgf@y{\pgfshapeminheight}% + \pgf@x=0.5\pgf@x + \pgf@y=0.5\pgf@y + } + % This is redundant, but makes some things easier: + \savedanchor\southwest{% + \pgfmathsetlength\pgf@x{\pgfshapeminwidth}% + \pgfmathsetlength\pgf@y{\pgfshapeminheight}% + \pgf@x=-0.5\pgf@x + \pgf@y=-0.5\pgf@y + } + % Inherit from rectangle + \inheritanchorborder[from=rectangle] + + % Define same anchor a normal rectangle has + \anchor{center}{\pgfpointorigin} + \anchor{north}{\northeast \pgf@x=0pt} + \anchor{east}{\northeast \pgf@y=0pt} + \anchor{south}{\southwest \pgf@x=0pt} + \anchor{west}{\southwest \pgf@y=0pt} + \anchor{north east}{\northeast} + \anchor{north west}{\northeast \pgf@x=-\pgf@x} + \anchor{south west}{\southwest} + \anchor{south east}{\southwest \pgf@x=-\pgf@x} + \anchor{text}{ + \pgfpointorigin + \advance\pgf@x by -.5\wd\pgfnodeparttextbox% + \advance\pgf@y by -.5\ht\pgfnodeparttextbox% + \advance\pgf@y by +.5\dp\pgfnodeparttextbox% + } + + % Define anchors for signal ports + \anchor{D}{ + \pgf@process{\northeast}% + \pgf@x=-1\pgf@x% + \pgf@y=.5\pgf@y% + } + \anchor{CLK}{ + \pgf@process{\northeast}% + \pgf@x=-1\pgf@x% + \pgf@y=-.5\pgf@y% + } + \anchor{Q}{ + \pgf@process{\northeast}% + \pgf@y=.5\pgf@y% + } + \anchor{Qn}{ + \pgf@process{\northeast}% + \pgf@y=-.5\pgf@y% + } + % Draw the rectangle box and the port labels + \backgroundpath{ + % Rectangle box + \pgfpathrectanglecorners{\southwest}{\northeast} + + % Draw port labels + \begingroup + \tikzset{flip flop/port labels} % Use font from this style + \tikz@textfont + + \pgf@anchor@latch@D + \pgftext[left,base,at={\pgfpoint{\pgf@x}{\pgf@y}},x=\pgfshapeinnerxsep]{\raisebox{-0.75ex}{D}} + + \pgf@anchor@latch@CLK + \pgftext[left,base,at={\pgfpoint{\pgf@x}{\pgf@y}},x=\pgfshapeinnerxsep]{\raisebox{-0.75ex}{C}} + + \pgf@anchor@latch@Q + \pgftext[right,base,at={\pgfpoint{\pgf@x}{\pgf@y}},x=-\pgfshapeinnerxsep]{\raisebox{-.75ex}{Q}} + + \pgf@anchor@latch@Qn + \pgftext[right,base,at={\pgfpoint{\pgf@x}{\pgf@y}},x=-\pgfshapeinnerxsep]{\raisebox{-.75ex}{$\overline{\mbox{Q}}$}} + + \endgroup + } +} + +% Register mit Enable +\pgfdeclareshape{reg}{ + % The 'minimum width' and 'minimum height' keys, not the content, determine + % the size + \savedanchor\northeast{% + \pgfmathsetlength\pgf@x{\pgfshapeminwidth}% + \pgfmathsetlength\pgf@y{\pgfshapeminheight}% + \pgf@x=0.5\pgf@x + \pgf@y=0.5\pgf@y + } + % This is redundant, but makes some things easier: + \savedanchor\southwest{% + \pgfmathsetlength\pgf@x{\pgfshapeminwidth}% + \pgfmathsetlength\pgf@y{\pgfshapeminheight}% + \pgf@x=-0.5\pgf@x + \pgf@y=-0.5\pgf@y + } + % Inherit from rectangle + \inheritanchorborder[from=rectangle] + + % Define same anchor a normal rectangle has + \anchor{center}{\pgfpointorigin} + \anchor{north}{\northeast \pgf@x=0pt} + \anchor{east}{\northeast \pgf@y=0pt} + \anchor{south}{\southwest \pgf@x=0pt} + \anchor{west}{\southwest \pgf@y=0pt} + \anchor{north east}{\northeast} + \anchor{north west}{\northeast \pgf@x=-\pgf@x} + \anchor{south west}{\southwest} + \anchor{south east}{\southwest \pgf@x=-\pgf@x} + \anchor{text}{ + \pgfpointorigin + \advance\pgf@x by -.5\wd\pgfnodeparttextbox% + \advance\pgf@y by -.5\ht\pgfnodeparttextbox% + \advance\pgf@y by +.5\dp\pgfnodeparttextbox% + } + + % Define anchors for signal ports + \anchor{D}{ + \pgf@process{\northeast}% + \pgf@x=-1\pgf@x% + \pgf@y=.5\pgf@y% + } + \anchor{CLK}{ + \pgf@process{\northeast}% + \pgf@x=-1\pgf@x% + \pgf@y=-.5\pgf@y% + } + \anchor{EN}{ + \pgf@process{\northeast}% + \pgf@x=-1\pgf@x% + \pgf@y=-0.0\pgf@y% + } + \anchor{Q}{ + \pgf@process{\northeast}% + \pgf@y=.5\pgf@y% + } +% \anchor{Qn}{ +% \pgf@process{\northeast}% +% \pgf@y=-.5\pgf@y% +% } +% \anchor{R}{ +% \pgf@process{\northeast}% +% \pgf@x=0pt% +% } +% \anchor{S}{ +% \pgf@process{\northeast}% +% \pgf@x=0pt% +% \pgf@y=-\pgf@y% +% } + % Draw the rectangle box and the port labels + \backgroundpath{ + % Rectangle box + \pgfpathrectanglecorners{\southwest}{\northeast} + % Angle (>) for clock input + \pgf@anchor@reg@CLK + \pgf@xa=\pgf@x \pgf@ya=\pgf@y + \pgf@xb=\pgf@x \pgf@yb=\pgf@y + \pgf@xc=\pgf@x \pgf@yc=\pgf@y + \pgfmathsetlength\pgf@x{1ex} % size depends on font size + \pgfmathsetlength\pgf@y{0.5ex} + \advance\pgf@ya by \pgf@y + \advance\pgf@xb by \pgf@x + \advance\pgf@yc by -\pgf@y + \pgfpathmoveto{\pgfpoint{\pgf@xa}{\pgf@ya}} + \pgfpathlineto{\pgfpoint{\pgf@xb}{\pgf@yb}} + \pgfpathlineto{\pgfpoint{\pgf@xc}{\pgf@yc}} + \pgfclosepath + + % Draw port labels + \begingroup + \tikzset{flip flop/port labels} % Use font from this style + \tikz@textfont + + \pgf@anchor@reg@D + \pgftext[left,base,at={\pgfpoint{\pgf@x}{\pgf@y}},x=\pgfshapeinnerxsep]{\raisebox{-0.75ex}{D}} + + \pgf@anchor@reg@EN + \pgftext[left,base,at={\pgfpoint{\pgf@x}{\pgf@y}},x=\pgfshapeinnerxsep]{\raisebox{-0.75ex}{EN}} + + \pgf@anchor@reg@Q + \pgftext[right,base,at={\pgfpoint{\pgf@x}{\pgf@y}},x=-\pgfshapeinnerxsep]{\raisebox{-.75ex}{Q}} + +% \pgf@anchor@reg@Qn +% \pgftext[right,base,at={\pgfpoint{\pgf@x}{\pgf@y}},x=-\pgfshapeinnerxsep]{\raisebox{-.75ex}{$\overline{\mbox{Q}}$}} + +% \pgf@anchor@reg@R + % \pgftext[top,at={\pgfpoint{\pgf@x}{\pgf@y}},y=-\pgfshapeinnerysep]{R} + +% \pgf@anchor@reg@S +% \pgftext[bottom,at={\pgfpoint{\pgf@x}{\pgf@y}},y=\pgfshapeinnerysep]{S} + \endgroup + } +} + +% Multiplexer +\pgfdeclareshape{mux}{ + % The 'minimum width' and 'minimum height' keys, not the content, determine + % the size + \savedanchor\northeast{% + \pgfmathsetlength\pgf@x{\pgfshapeminwidth}% + \pgfmathsetlength\pgf@y{\pgfshapeminheight}% + \pgf@x=0.5\pgf@x + \pgf@y=0.5\pgf@y + } + % This is redundant, but makes some things easier: + \savedanchor\southwest{% + \pgfmathsetlength\pgf@x{\pgfshapeminwidth}% + \pgfmathsetlength\pgf@y{\pgfshapeminheight}% + \pgf@x=-0.5\pgf@x + \pgf@y=-0.5\pgf@y + } + % Inherit from rectangle + \inheritanchorborder[from=rectangle] + + % Define same anchor a normal rectangle has + \anchor{center}{\pgfpointorigin} + \anchor{north}{\northeast \pgf@x=0pt} + \anchor{east}{\northeast \pgf@y=0pt} + \anchor{south}{\southwest \pgf@x=0pt} + \anchor{west}{\southwest \pgf@y=0pt} + \anchor{north east}{\northeast} + \anchor{north west}{\northeast \pgf@x=-\pgf@x} + \anchor{south west}{\southwest} + \anchor{south east}{\southwest \pgf@x=-\pgf@x} + \anchor{text}{ + \pgfpointorigin + \advance\pgf@x by -.5\wd\pgfnodeparttextbox% + \advance\pgf@y by -.5\ht\pgfnodeparttextbox% + \advance\pgf@y by +.5\dp\pgfnodeparttextbox% + } + + % Define anchors for signal ports + \anchor{izero}{ + \pgf@process{\northeast}% + \pgf@x=-1\pgf@x% + \pgf@y=.5\pgf@y% + } + \anchor{ione}{ + \pgf@process{\northeast}% + \pgf@x=-1\pgf@x% + \pgf@y=-.5\pgf@y% + } + \anchor{sel}{ + \pgf@process{\northeast}% + \pgf@x=0pt% + \pgf@y=-.75\pgf@y% + } +% \anchor{CE}{ +% \pgf@process{\northeast}% +% \pgf@x=-1\pgf@x% +% \pgf@y=-0.33333\pgf@y% +% } + \anchor{output}{ + \pgf@process{\northeast}% + \pgf@y=0pt% + } + % Draw the rectangle box and the port labels + \backgroundpath{ + % Rectangle box + %\pgfpathrectanglecorners{\southwest}{\northeast} + %Draw the mux + \southwest + \pgf@xa=\pgf@x \pgf@ya=-\pgf@y + \pgf@xb=-\pgf@x \pgf@yb=-.5\pgf@y + \pgf@xc=-\pgf@x \pgf@yc=.5\pgf@y + + \pgfmoveto{\southwest} + \pgfpathlineto{\pgfpoint{\pgf@xa}{\pgf@ya}} + \pgfpathlineto{\pgfpoint{\pgf@xb}{\pgf@yb}} + \pgfpathlineto{\pgfpoint{\pgf@xc}{\pgf@yc}} + \pgfclosepath + + % Draw port labels + \begingroup + \tikzset{flip flop/port labels} % Use font from this style + \tikz@textfont + + \pgf@anchor@mux@izero + \pgftext[left,base,at={\pgfpoint{\pgf@x}{\pgf@y}},x=\pgfshapeinnerxsep]{\raisebox{-0.75ex}{0}} + + \pgf@anchor@mux@ione + \pgftext[left,base,at={\pgfpoint{\pgf@x}{\pgf@y}},x=\pgfshapeinnerxsep]{\raisebox{-0.75ex}{1}} + + + + \endgroup + } +} + + + +% Key to add font macros to the current font +\tikzset{add font/.code={\expandafter\def\expandafter\tikz@textfont\expandafter{\tikz@textfont#1}}} + +% Define default style for this node +%\tikzset{flip flop/port labels/.style={font=\sffamily\tiny}} +\tikzset{flip flop/port labels/.style={font=\tiny}} +\tikzset{every dff node/.style={draw,minimum width=8mm,minimum +height=10mm,thin,inner sep=0.5mm,outer sep=0pt,cap=round}}%,add font=\sffamily}} + +\tikzset{every ff node/.style={draw,minimum width=8mm,minimum +height=10mm,thin,inner sep=0.5mm,outer sep=0pt,cap=round}}%,add font=\sffamily}} + + +\tikzset{every latch node/.style={draw,minimum width=8mm,minimum +height=10mm,thin,inner sep=0.5mm,outer sep=0pt,cap=round}}%,add font=\sffamily}} + +\tikzset{every mux node/.style={draw,minimum width=5mm,minimum +height=10mm,thin,inner sep=0.5mm,outer sep=0pt,cap=round}}%,add font=\sffamily}} + + +\tikzset{every reg node/.style={draw,minimum width=12mm,minimum +height=10mm,thin,inner sep=0.5mm,outer sep=0pt,cap=round}}%,add font=\sffamily}} + +\makeatother |