2020/3/19第五章组合逻辑电路设计5.1门电路5.2编码器5.3优先编码器5.4译码器5.5多路选择器5.6数值比较器5.7加法器在前面的各章里,分别介绍了VHDL语言的语句、语法以及利用VHDL语言设计硬件电路的基本方法,本章重点介绍利用VHDL语言设计基本组合逻辑模块的方法。5.1门电路二输入异或门二输入异或门的逻辑表达式如下所示:babay二输入异或门的逻辑符号如图所示,真值表如下表所示:bya=1aby000011101110例:采用行为描述方式设计的异或门(依据逻辑表达式)LIBRARYIEEE;USEIEEE.STD_LOGIC_1164.ALL;ENTITYxor2_v1ISPORT(a,b:INSTD_LOGIC;y:OUTSTD_LOGIC);ENDxor2_v1;ARCHITECTUREbehaveOFxor2_v1ISBEGINy=aXORb;ENDbehave;例:采用数据流描述方式设计的异或门(依据真值表)LIBRARYIEEE;USEIEEE.STD_LOGIC_1164.ALL;ENTITYxor2_v2ISPORT(a,b:INSTD_LOGIC;y:OUTSTD_LOGIC);ENDxor2_v2;ARCHITECTUREdataflowOFxor2_v2ISBEGINPROCESS(a,b)VARIABLEcomb:STD_LOGIC_VECTOR(1DOWNTO0);BEGINcomb:=a&b;2020/3/19CASEcombISWHEN00=y='0';WHEN01=y='1';WHEN10=y='1';WHEN11=y='0';WHENOTHERS=y='X';ENDCASE;ENDPROCESS;ENDdataflow;2020/3/19二输入异或门的仿真波形5.2编码器用一组二进制代码按一定规则表示给定字母、数字、符号等信息的方法称为编码,能够实现这种编码功能的逻辑电路称为编码器。IIIIIIII01324567AAA0128线-3线编码器I0I1I2I3I4I5I6I7A2A1A010000000000010000000010010000001000010000011000010001000000010010100000010110000000011118线—3线编码器真值表输入输出8线—3线编码器逻辑表达式:A2=I4+I5+I6+I7A1=I2+I3+I6+I7A0=I1+I3+I5+I7例:采用行为描述方式的8线—3线编码器VHDL源代码(依据逻辑表达式)LIBRARYIEEE;USEIEEE.STD_LOGIC_1164.ALL;ENTITYcoder83_v1ISPORT(I0,I1,I2,I3,I4,I5,I6,I7:INSTD_LOGIC;A0,A1,A2:OUTSTD_LOGIC);ENDcoder83_v1;ARCHITECTUREbehaveOFcoder83_v1ISBEGINA2=I4ORI5ORI6ORI7;A1=I2ORI3ORI6ORI7;A0=I1ORI3ORI5ORI7;ENDbehave;采用行为描述方式的8线—3线编码器仿真波形例:采用数据流描述方式的8线—3线编码器VHDL源代码(依据真值表)LIBRARYIEEE;USEIEEE.STD_LOGIC_1164.ALL;ENTITYcoder83_v2ISPORT(I:INSTD_LOGIC_VECTOR(7DOWNTO0);A:OUTSTD_LOGIC_VECTOR(2DOWNTO0));ENDcoder83_v2;ARCHITECTUREdataflowOFcoder83_v2ISBEGINPROCESS(I)BEGINCASEIISWHEN10000000=A=111;WHEN01000000=A=110;WHEN00100000=A=101;WHEN00010000=A=100;WHEN00001000=A=011;WHEN00000100=A=010;WHEN00000010=A=001;WHENOTHERS=A=000;ENDCASE;ENDPROCESS;ENDdataflow;采用数据流描述方式的8线—3线编码器仿真波形(总线显示方式)5.3优先编码器1优先编码器II7I6II0III8线-3线432574148GSEOAA21A0EIEII0I1I2I3I4I5I6I7A2A1A0GSEO1××××××××11111011111111111100×××××××0000010××××××01001010×××××011010010××××0111011010×××01111100010××011111101010×01111111100100111111111101输入输出74148优先编码器真值表(反码编码方案)456701234567123456723456734567012345672)(IIIIEIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIEIEIA46756723670123456712345674567567012345671)(IIIIIIIIIIEIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIEIEIA135745723576701234567234567456767012345670)(IIIIIIIIIIIIIEIIIIIIIIIIIIIIIIIIIIIIIIIIIIIEIEIA各输出端的逻辑方程0123456701234567IIIIIIIIEIIIIIIIIIEIEIGS01234567IIIIIIIIEIEO以74148逻辑表达式为依据,按行为描述方式编写的VHDL源代码如下:LIBRARYIEEE;USEIEEE.STD_LOGIC_1164.ALL;ENTITYprioritycoder83_v1ISPORT(I7,I6,I5,I4,I3,I2,I1,I0:INSTD_LOGIC;EI:INSTD_LOGIC;A2,A1,A0:OUTSTD_LOGIC;GS,EO:OUTSTD_LOGIC);ENDprioritycoder83_v1;ARCHITECTUREbehaveOFprioritycoder83_v1ISBEGINA2=EIOR(I7ANDI6ANDI5ANDI4);A1=EIOR(I7ANDI6ANDI3ANDI2)OR(I7ANDI6ANDNOTI5)OR(I7ANDI6ANDNOTI4);A0=EIOR(I7ANDNOTI6)OR(I7ANDI5ANDNOTI4)OR(I7ANDI5ANDI3ANDI1)OR(I7ANDI5ANDI3ANDNOTI2);GS=EIOR(I7ANDI6ANDI5ANDI4ANDI3ANDI2ANDI1ANDI0);EO=EIORNOT(I7ANDI6ANDI5ANDI4ANDI3ANDI2ANDI1ANDI0);ENDbehave;74148优先编码器的仿真波形注意:采用数据流编写优先编码器时,因为VHDL语言目前还不能描述任意项,即下面的语句形式是非法的:WHEN“0XXXXXXX”=A=“000”;因此不能用CASE语句来描述74148。采用IF语句对74148进行了逻辑描述如下:LIBRARYIEEE;USEIEEE.STD_LOGIC_1164.ALL;ENTITYprioritycoder83_v2ISPORT(I:INSTD_LOGIC_VECTOR(7DOWNTO0);EI:INSTD_LOGIC;A:OUTSTD_LOGIC_VECTOR(2DOWNTO0);GS,EO:OUTSTD_LOGIC);ENDprioritycoder83_v2;ARCHITECTUREdataflowOFprioritycoder83_v2ISBEGINPROCESS(EI,I)BEGINIF(EI='1')THENA=111;GS='1';EO='1';ELSIF(I=11111111ANDEI='0')THENA=111;GS='1';EO='0';ELSIF(I(7)='0'ANDEI='0')THENA=000;GS='0';EO='1';ELSIF(I(6)='0'ANDEI='0')THENA=001;GS='0';EO='1';ELSIF(I(5)='0'ANDEI='0')THENA=010;GS='0';EO='1';ELSIF(I(4)='0'ANDEI='0')THENA=011;GS='0';EO='1';ELSIF(I(3)='0'ANDEI='0')THENA=100;GS='0';EO='1';ELSIF(I(2)='0'ANDEI='0')THENA=101;GS='0';EO='1';ELSIF(I(1)='0'ANDEI='0')THENA=110;GS='0';EO='1';ELSE(I(0)='0'ANDEI='0')THENA=111;GS='0';EO='1';ENDIF;ENDPROCESS;ENDdataflow;74148优先编码器的仿真波形(总线方式)5.4译码器译码器3线-8线741380AA1A2G1GG2A2B27Y40Y1YYYYYY653G1G2AG2BA2A1A0Y0Y1Y2Y3Y4Y5Y6Y7×1××××11111111××1×××111111110×××××111111111000000111111110000110111111100010110111111000111110111110010011110111100101111110111001101111110110011111111110输入输出3线—8线译码器74138真值表按数据流描述方式编写的3线—8线译码器74138VHDL源代码LIBRARYIEEE;USEIEEE.STD_LOGIC_1164.ALL;ENTITYdecoder138_v2ISPORT(G1,G2A,G2B:INSTD_LOGIC;A:INSTD_LOGIC_VECTOR(2DOWNTO0);Y:OUTSTD_LOGIC_VECTOR(7DOWNTO0));ENDdecoder138_v2;ARCHITECTUREdataflowOFdecoder138_v2ISBEGINPROCESS(G1,G2A,G2B,A)BEGINIF(G1='1'ANDG2A='0'ANDG2B='0')THENCASEAISWHEN000=Y=11111110;WHEN001=Y=11111101;WHEN010=Y=11111011;WHEN011=Y=11110111;WHEN100=Y=11101111;WHEN101=Y=11011111;WHEN110=Y=10111111;WHENOTHERS=Y=01111111;ENDCASE;ELSEY=11111111;ENDIF;ENDPROCESS;ENDdataflow;总线显示方式的3线—8线译码器74138仿真波形图5.5多路选择器DG0DD1Y8选1数据选择器D741513DDY5D4276D10AA2A使能地址选择YYbGA2A1A01×××010000D0D00001D1D10010D2D20011D3D30100D4D40101D5D50110D6D60111D7D7输入输出741518选1数据选择器真值表参考74151的真值表,采用IF语句结构编写的VHDL源代码如下:LIBRARYIEEE;USEIEEE.STD_LOGIC_1164.ALL;ENTITYmux8_v2ISPORT(A:INSTD_LOGIC_VECTOR(2DOWNTO0)