您的当前位置:首页正文

数字逻辑习题

2020-10-28 来源:客趣旅游网
1. 分析下图所示逻辑电路,其中S3、S2、S1、S0为控制输入端,列出真值表,说明 F 与 A、B 的关系。

F1=

ABSBS021

F2=ABSF=F1F2=AABS03

1BSBSF1AA BA B0

S1 S00 00 11 01 1S3 S20 00 11 01 1F21A+BA+BAS3 S2 S1 S00 0 ×0 1 ×1 0 ×1 1 ×××××F=F1F2F1F1F1F1S3 S2 S1 S0××××××××0 00 11 01 1F=F1F2AA BA B0

9. 用红、黄、绿三个指示灯表示三台设备的工作情况:绿灯亮表示全部正常;红灯 亮表示有一台不正常;黄灯亮表示有两台不正常;红、黄灯全亮表示三台都不正常。列出控制电路真值表,并选出合适的集成电路来实现。

解:

设:三台设备分别为 A、B、C: “1”表示有故障,“0”表示无故障;红、黄、绿灯分别为Y1、Y2、Y3:“1”表示灯亮;“0”表示灯灭。据题意列出真值表如下:

A B C 0 0 00 0 10 1 00 1 11 0 01 0 11 1 01 1 1Y1 Y2 Y30 0 11 0 01 0 00 1 01 0 00 1 00 1 01 1 0

Y1ABCY2BCA(BC)于是得:Y3ABCABC

10. 用两片双四选一数据选择器和与非门实现循环码至8421BCD码转换。

解:(1)函数真值表、卡诺图如下;

(2)画逻辑图:

11. 用一片74LS148和与非门实现8421BCD优先编码器

8:3优先编码器I0I2I4I6I8I9I1I3I5I701234567ENY0Y1Y2Y0Y1Y2Y3

ST18. 设计一个血型配比指示器。解: 用XY表示供血者代码,MN表示受血者代码。代码设定如下: XY = 00 A型 MN = 00 A型 01 B型 01 B型 10 AB型 10 AB型 11 O 型 11 O 型

X Y0 00 00 00 00 10 10 10 11 01 01 01 01 11 11 11 1M N0 00 11 01 10 00 11 01 10 00 11 01 10 00 11 01 1F1(绿)F2(红)10100110001011110101100111010000得:F1 = Σ(0,2,5,6,10,12,13,14,15)

F2F1

9. 用D触发器构成按循环码(000→001→011→111→101→100→000)规律工作的六进制同步计数器

解:先列出真值表,然后求得激励方程

化简得:

ZQ2Q0Q2Q1

2nnnnn1Q1Q2Q0Q2Q0nnnnn1Q0n1Q2Q1n12n1n1n

nn02DQDQ1QQQQQn2n2n0n11n10DQ0QQ

14. 分析下图所示同步时序逻辑电路,作出状态转移表和状态图,说明这个电路能对何种序列进行检测?

解:电路的状态方程和输出方程为:

0/0X/Z000/00/11/0Q2n Q1n0 00 11 01 1Q2n+1 Q1n+1/ ZX =000 / 000 / 100 / 000 / 1X =101 / 011 / 011 / 011 / 0011/00/11/01011

1/0

由此可见,凡输入序列 “110”,输出就为“1” 。

15. 作“101”序列信号检测器的状态表,凡收到输入序列101时,输出为 1 ;并规定检测的101序列不重叠。

1/1 解: 根据题意分析,输入为二进制序列x,输出为Z;且电路应具有3个状态: S0、S1、S2。列状态图和状态表如下: 0/0 PS NS / S0 Z X =0 X =1

1/0 0/0 S0 S0 S1

S2

S0 / 0 S2 / 0 S0 / 0

S1 / 0 S1 / 0 S0 / 1

1/0 0/0 S0

12 若将下图接成12进制加法器,预置值应为多少?画出状态图及输出波形图。

解:预置值应C=0,B=1,A=1。

序号0123456789101112131415QD QC QB QA0 0 0 00 0 0 10 0 1 00 0 1 10 1 0 00 1 0 10 1 1 00 1 1 11 0 0 01 0 0 11 0 1 01 0 1 11 1 0 01 1 0 11 1 1 01 1 1 1

0000→ 0011→ 0100→ 0101→ 0110→ 0111↑↓

1111← 1110← 1101← 1100← 1011← 1000ENPENTQDQCQBQACOLD74LS169D CBA0 1 1UDCP

1. 用VHDL写出4输入与门 解: 源代码:

LIBRARY IEEE;

USE IEEE.STD_LOGIC_1164.ALL;

ENTITY and4 IS

PORT (a,b,c,d:IN STD_LOGIC; x:OUT STD_LOGIC); END and4;

ARCHITECTURE and4_arc OF and4 IS BEGIN

x<=a AND b AND c AND d; END and4_arc;

2. 用VHDL写出4输入或门 解: 源代码:

LIBRARY IEEE;

USE IEEE.STD_LOGIC_1164.ALL;

ENTITY or4 IS

PORT (a,b,c,d:IN STD_LOGIC; x:OUT STD_LOGIC); END or4;

ARCHITECTURE or4_arc OF or4 IS BEGIN

x<=a OR b OR c OR d; END or4_arc;

3. 用VHDL写出SOP表达式 解: 源代码:

LIBRARY IEEE;

USE IEEE.STD_LOGIC_1164.ALL;

ENTITY sop IS

PORT (a,b,c,d,e,f:IN STD_LOGIC; x:OUT STD_LOGIC); END sop;

ARCHITECTURE sop_arc OF sop IS BEGIN

x<=(a AND b) OR (c AND d) OR (e AND f); END sop_arc;

4. 用VHDL写出布尔表达式 解: 源代码:

LIBRARY IEEE;

USE IEEE.STD_LOGIC_1164.ALL;

ENTITY boolean IS

PORT (a,b,c:IN STD_LOGIC; f:OUT STD_LOGIC); END boolean ;

ARCHITECTURE boolean_arc OF boolean IS BEGIN

f<=(a OR (NOT b) OR c) AND (a OR b OR (NOT c)) AND ((NOT a) OR (NOT b) OR (NOT c));

END boolean_arc;

5. 用VHDL结构法写出SOP表达式 解: 源代码:

――三输入与非门的逻辑描述 LIBRARY IEEE;

USE IEEE.STD_LOGIC_1164.ALL;

ENTITY nand3 IS

PORT (a,b,c:IN STD_LOGIC; x:OUT STD_LOGIC); END nand3;

ARCHITECTURE nand3_arc OF nand3 IS BEGIN

x<=NOT (a AND b AND c); END nand3_arc;

――顶层结构描述文件 LIBRARY IEEE;

USE IEEE.STD_LOGIC_1164.ALL;

ENTITY sop IS

PORT (in1,in2,in3,in4,in5,in6,in7,in8,in9:IN STD_LOGIC; out4:OUT STD_LOGIC); END sop;

ARCHITECTURE sop_arc OF sop IS COMPONENT nand3

PORT (a,b,c:IN STD_LOGIC; x:OUT STD_LOGIC); END COMPONENT;

SIGNAL out1,out2,out3:STD_LOGIC; BEGIN

u1:nand3 PORT MAP (in1,in2,in3,out1); u2:nand3 PORT MAP (in4,in5,in6,out2); u3:nand3 PORT MAP (in7,in8,in9,out3); u4:nand3 PORT MAP (out1,out2,out3,out4); END sop;

6. 用VHDL数据流法写出SOP表达式 解: 源代码:

LIBRARY IEEE;

USE IEEE.STD_LOGIC_1164.ALL;

ENTITY sop IS

PORT (in1,in2,in3,in4,in5,in6,in7,in8,in9:IN STD_LOGIC; out4:OUT STD_LOGIC); END sop;

ARCHITECTURE sop_arc OF sop IS BEGIN

out4<=(in1 AND in2 AND in3) OR (in4 AND in5 AND in6 ) OR (in7 AND in8 AND in9); END sop_arc;

13. 用VHDL设计3-8译码器 解: 源代码:

LIBRARY IEEE;

USE IEEE.STD_LOGIC_1164.ALL;

ENTITY decoder_3_to_8 IS

PORT (a,b,c,g1,g2a,g2b:IN STD_LOGIC;

y:OUT STD_LOGIC _VECTOR(7 downto 0)); END decoder_3_to_8;

ARCHITECTURE rt1 OF decoder_3_to_8 IS

SIGNAL indata:STD_LOGIC _VECTOR(2 downto 0); BEGIN

indata<=c & b & a;

PROCESS(indata,g1,g2a,g2b) BEGIN

IF(g1=′1′ AND g2a=′0′ AND g2b=′0′)THEN CASE indata IS

WHEN \"000\"=>y<=\"11111110\"; WHEN \"001\"=>y<=\"11111101\"; WHEN \"010\"=>y<=\"11111011\"; WHEN \"011\"=>y<=\"11110111\"; WHEN \"100\"=>y<=\"11101111\"; WHEN \"101\"=>y<=\"11011111\"; WHEN \"110\"=>y<=\"10111111\"; WHEN others=>y<=\"01111111\"; END CASE; ELSE

y<=\"11111111\"; END IF; END PROCESS; END rt1;

14. 用VHDL设计七段显示译码器 解: 源代码:

LIBRARY IEEE;

USE IEEE.STD_LOGIC_1164.ALL;

ENTITY segment7 IS

PORT (xin:IN STD_LOGIC _VECTOR(3 downto 0); lt,rbi:IN STD_LOGIC;

yout:OUT STD_LOGIC _VECTOR(6 downto 0);

birbo:INOUT STD_LOGIC);

END segment7;

ARCHITECTURE seg7448 OF segment7 IS

SIGNAL sig_xin: STD_LOGIC _VECTOR(3 downto 0); BEGIN

sig_xin<=xin;

PROCESS(sig_xin,lt,rbi,birbo) BEGIN

IF(birbo=′0′)THEN

yout<=\"0000000\"; ELSIF (lt=′0′)THEN yout<=\"1111111\"; birbo<=′1′;

ELSIF (rbi=′0′ AND sig_xin=\"0000\")THEN yout<=\"0000000\"; birbo<=′0′;

ELSIF (rbi=′1′ AND sig_xin=\"0000\")THEN yout<=\"1111110\"; birbo<=′1′; ELSE

birbo<=′1′;

CASE sig_xin IS

WHEN \"0001\"=>yout<=\"0110000\"; WHEN \"0010\"=>yout<=\"1101101\"; WHEN \"0011\"=>yout<=\"1111001\"; WHEN \"0100\"=>yout<=\"0110011\"; WHEN \"0101\"=>yout<=\"1011011\"; WHEN \"0110\"=>yout<=\"0011111\"; WHEN \"0111\"=>yout<=\"1110000\"; WHEN \"1000\"=>yout<=\"1111111\"; WHEN \"1001\"=>yout<=\"1110011\"; WHEN others=>yout<=\"0100011\";

END CASE; END IF; END PROCESS; END seg7448;

15. 用VHDL设计8/3优先编码器 解: 源代码:

LIBRARY IEEE;

USE IEEE.STD_LOGIC_1164.ALL;

ENTITY priorityencoder IS

PORT (din:IN STD_LOGIC _VECTOR(7 downto 0); ei:IN STD_LOGIC;

yout:OUT STD_LOGIC _VECTOR(2 downto 0);

eo,gs:OUT STD_LOGIC);

END priorityencoder;

ARCHITECTURE cod74148 OF priorityencoder IS BEGIN

PROCESS(ei,din) BEGIN

IF(ei=′1′)THEN yout<=\"111\"; eo<=′1′; gs<=′1′; ELSE

IF (din(7)=′0′ ) THEN

yout<=\"000\"; eo<=′1′; gs<=′0′;

ELSIF (din(6)=′0′ ) THEN

yout <=\"001\"; eo<=′1′; gs<=′0′;

ELSIF (din(5)=′0′ ) THEN

yout<=\"010\"; eo<=′1′; gs<=′0′;

ELSIF (din(4)=′0′ ) THEN

yout<=\"011\"; eo<=′1′; gs<=′0′;

ELSIF (din(3)=′0′ ) THEN

yout<=\"100\"; eo<=′1′; gs<=′0′;

ELSIF (din(2)=′0′ ) THEN

yout<=\"101\"; eo<=′1′; gs<=′0′;

ELSIF (din(1)=′0′ ) THEN

yout<=\"110\"; eo<=′1′; gs<=′0′;

ELSIF (din(0)=′0′ ) THEN

yout<=\"111\"; eo<=′1′; gs<=′0′;

ELSIF (din=\"11111111\") THEN

yout<=\"111\";

eo<=′0′; gs<=′1′; END IF; END IF; END PROCESS; END cod74148;

16. 用VHDL设计BCD码至二进制码转换器。 解: 源代码: library ieee;

use ieee.std_logic_1164.all;

entity bcdtobi is port(

bcdcode : IN STD_LOGIC_VECTOR(7 DOWNTO 0); start: in std_logic;

qbit : OUT STD_LOGIC_VECTOR(3 DOWNTO 0) ); end;

architecture behavioral of bcdtobi is begin

process(start,bcdcode) begin if start='0' then case bcdcode(7 downto 0) is when \"00000000\"=>qbit(3 downto 0)<=\"0000\"; when \"00000001\"=>qbit(3 downto 0)<=\"0001\"; when \"00000010\"=>qbit(3 downto 0)<=\"0010\"; when \"00000011\"=>qbit(3 downto 0)<=\"0011\"; when \"00000100\"=>qbit(3 downto 0)<=\"0100\"; when \"00000101\"=>qbit(3 downto 0)<=\"0101\"; when \"00000110\"=>qbit(3 downto 0)<=\"0110\"; when \"00000111\"=>qbit(3 downto 0)<=\"0111\"; when \"00001000\"=>qbit(3 downto 0)<=\"1000\"; when \"00001001\"=>qbit(3 downto 0)<=\"1001\"; when \"00010000\"=>qbit(3 downto 0)<=\"1010\"; when \"00010001\"=>qbit(3 downto 0)<=\"1011\"; when \"00010010\"=>qbit(3 downto 0)<=\"1100\"; when \"00010011\"=>qbit(3 downto 0)<=\"1101\"; when \"00010100\"=>qbit(3 downto 0)<=\"1110\"; when \"00010101\"=>qbit(3 downto 0)<=\"1111\"; when others=>qbit(3 downto 0)<=\"0000\"; end case; else qbit(3 downto 0)<=\"0000\"; end if; end process; end behavioral;

17. 用VHDL设计4位寄存器 解: 异步复位

源代码:

LIBRARY IEEE;

USE IEEE.STD_LOGIC_1164.ALL;

ENTITY register_4 IS

PORT (clk,r:IN STD_LOGIC;

din:IN STD_LOGIC _VECTOR(3 downto 0);

qout:OUT STD_LOGIC _VECTOR(3 downto 0)); END register_4;

ARCHITECTURE rge_arc OF register_4 IS

SIGNAL q_temp:STD_LOGIC _VECTOR(3 downto 0); BEGIN

PROCESS(clk,r) BEGIN

IF(r=′1′)THEN

q_temp<=\"0000\";

ELSIF (clk′event AND clk=′1′ ) THEN

q_temp<=din; END IF; qout<=q_temp; END PROCESS; END rge_arc;

18. 用VHDL设计4位双向移位寄存器

解: s1、s0控制工作方式,dsl为左移数据输入,dsr为右移数据输入。

源代码:

LIBRARY IEEE;

USE IEEE.STD_LOGIC_1164.ALL;

ENTITY shiftreg IS

PORT (clk,r,dsr,dsl:IN STD_LOGIC;

s1,s0:IN STD_LOGIC;--function select

din:IN STD_LOGIC _VECTOR(3 downto 0);--data in

qout:OUT STD_LOGIC _VECTOR(3 downto 0));--data out END shiftreg;

ARCHITECTURE ls74194 OF shiftreg IS

SIGNAL iq: STD_LOGIC _VECTOR(3 downto 0); SIGNAL s:STD_LOGIC _VECTOR(1 downto 0); BEGIN

s<=s1 & s0;

PROCESS(clk,r) BEGIN

IF(r=′0′)THEN iq<=\"0000\";

ELSIF (clk′event AND clk=′1′ ) THEN

CASE s IS

WHEN \"00\"=>null;

WHEN \"01\"=>iq<=dsr & din(3 downto 1);--right WHEN \"10\"=>iq<=din(2 downto 0)& dsl;--left WHEN \"11\"=>iq<=din;--load WHEN others=>null; END CASE; END IF; END PROCESS; qout<=iq; END ls74194;

19. 用VHDL设计8421码十进制加法计数器 解: 异步清零,同步置数

源代码:

LIBRARY IEEE;

USE IEEE.STD_LOGIC_1164.ALL; USE IEEE.STD_LOGIC_ARITH.ALL;

USE IEEE.STD_LOGIC_UNSIGNED.ALL;

ENTITY count10 IS

PORT (clk,clr,load:IN STD_LOGIC;

din:IN STD_LOGIC _VECTOR(3 downto 0); co:OUT STD_LOGIC;

qout:OUT STD_LOGIC _VECTOR(3 downto 0)); END count10;

ARCHITECTURE count10_arch OF count10 IS SIGNAL iq: STD_LOGIC _VECTOR(3 downto 0); BEGIN

PROCESS(clr,clk,load) BEGIN

IF(clr=′0′)THEN iq<=\"0000\";

ELSIF (clk′event AND clk=′1′ ) THEN

IF(load=′0′)THEN iq<=din;

ELSIF(iq=9)THEN

iq<=\"0000\";

ELSE

iq<=iq+1;

END IF; END IF; END PROCESS; qout<=iq;

co<=′1′ WHEN iq=\"1001\" ELSE ′0′;

END count10_arch;

20.用VHDL设计可逆格雷码计数器 解: 源代码:

LIBRARY IEEE;

USE IEEE.STD_LOGIC_1164.ALL;

ENTITY gray_count IS

PORT (clk,y:IN STD_LOGIC;

qout:OUT STD_LOGIC _VECTOR(2 downto 0)); END gray_count;

ARCHITECTURE arch_gray OF gray_count IS

SIGNAL iq: STD_LOGIC _VECTOR(2 downto 0); BEGIN

PROCESS(clk) BEGIN

IF (clk′event AND clk=′1′ ) THEN

IF(y=′1′)THEN CASE iq IS

WHEN \"000\"=>iq<=\"001\"; WHEN \"001\"=>iq<=\"011\"; WHEN \"011\"=>iq<=\"010\"; WHEN \"010\"=>iq<=\"110\"; WHEN \"110\"=>iq<=\"111\"; WHEN \"111\"=>iq<=\"101\"; WHEN \"101\"=>iq<=\"100\"; WHEN others=>iq<=\"000\"; END CASE; END IF;

IF(y=′0′)THEN CASE iq IS

WHEN \"000\"=>iq<=\"100\"; WHEN \"100\"=>iq<=\"101\";

WHEN \"101\"=>iq<=\"111\"; WHEN \"111\"=>iq<=\"110\"; WHEN \"110\"=>iq<=\"010\"; WHEN \"010\"=>iq<=\"011\"; WHEN \"011\"=>iq<=\"001\"; WHEN others=>iq<=\"000\"; END CASE; END IF; END IF; END PROCESS;

qout<=iq;

END arch_gray;

21. 用VHDL设计有限状态机 解: 源代码:

LIBRARY IEEE;

USE IEEE.STD_LOGIC_1164.ALL;

ENTITY asm IS

PORT (clk,k,reset:IN STD_LOGIC;

qout:OUT STD_LOGIC _VECTOR(1 downto 0)); END asm;

ARCHITECTURE asm_arch OF asm IS TYPE asm_st IS (s0,s1,s2,s3);

SIGNAL current_state,next_state:asm_st; BEGIN

reg: PROCESS(clk,reset) BEGIN

IF (reset=′1′ ) THEN current_state<=s0;

ELSIF (clk′event AND clk=′1′ ) THEN

current_state<=next_state; END IF; END PROCESS;

com: PROCESS(current_state,k) BEGIN

CASE current_state IS

WHEN s0=>qout<=\"00\";

IF (k=′0′ ) THEN next_state<=s1; ELSE

next_state<=s0;

END IF;

WHEN s1=>qout<=\"01\";

IF (k=′0′ ) THEN next_state<=s1; ELSE

next_state<=s2;

END IF;

WHEN s2=>qout<=\"10\";

IF (k=′0′ ) THEN next_state<=s3; ELSE

next_state<=s2;

END IF;

WHEN s3=>qout<=\"11\";

IF (k=′0′ ) THEN next_state<=s3; ELSE

next_state<=s0;

END IF;

WHEN others=> next_state<=s0; END CASE; END PROCESS; END asm_arch;

21.设计一个彩灯控制器。 解:彩灯电路框图如下

12路彩灯A0„„A5B0„„B5控制电路CP

library ieee;

use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity light is port(clk1: in std_logic; ---时钟信号

light: buffer std_logic_vector(11 downto 0)); --输出 end light;

architecture behv of light is constant len: integer:=11; signal banner: std_logic:='0'; ----定义信号banner为两种节拍转换信号;

signal clk,clk2: std_logic; ----信号CLK,CLK2作为辅助时钟

begin

clk<=(clk1 and banner) or (clk2 and not banner); process(clk1) begin if clk1'event and clk1='1' then ---CLK1二分频得CLK2 clk2<=not clk2; end if; end process;

process(clk) ---- variable flag: bit_vector(3 downto 0):=\"0000\"; begin if clk'event and clk='1' then if flag=\"0000\" then light<='1' & light(len downto 1); ----顺序向右循环移位 if light(1)='1' then ----依次点亮 flag:=\"0001\"; end if; elsif flag=\"0001\" then ———依次熄灭 light<=light(len-1 downto 0) & '0'; if light(10)='0' then flag:=\"0010\";

end if;

elsif flag=\"0010\" then light<= light(len-1 downto 0) & '1'; ----顺序向左循环移位 if light(10)='1' then ----依次点亮 flag:=\"0011\"; end if; elsif flag=\"0011\" then ———依次熄灭 light<= '0' & light(len downto 1); if light(1)='0' then flag:=\"0100\"; end if; elsif flag=\"0100\" then light(len downto 6)<=light(len-1 downto 6)&'1'; ---从中间向两边点 light(len-6 downto 0)<='1'&light(len-6 downto 1); if light(1)='1' then flag:=\"0101\"; end if; elsif flag=\"0101\" then light(len downto 6)<='0'&light(len downto 7); ----从两边向中间熄 light(len-6 downto 0)<=light(len-7 downto 0)&'0'; if light(2)='0' then flag:=\"0110\";

end if;

elsif flag=\"0110\" then light(len downto 6)<='1'&light(len downto 7); ----奇 偶位循环点亮 light(len-6 downto 0)<='1'&light(len-6 downto 1); if light(1)='1' then flag:=\"0111\"; end if; elsif flag=\"0111\" then light<=\"000000000000\"; flag:=\"1000\"; elsif flag=\"1000\" then ----从新开始 banner<=not banner; ---banner信号转换,实现第二种节拍 flag:=\"0000\"; end if; end if; end process; end behv;

因篇幅问题不能全部显示,请点此查看更多更全内容