EDA程序设计试题及答案讲解.docx
《EDA程序设计试题及答案讲解.docx》由会员分享,可在线阅读,更多相关《EDA程序设计试题及答案讲解.docx(36页珍藏版)》请在冰豆网上搜索。
EDA程序设计试题及答案讲解
1.
请画出下段程序的真值表,并说明该电路的功能
LIBRARYieee;
USEieee.std_logic_1164.all;
ENTITYaaaIS
输出
x3
x2
x1
x0
0
0
0
1
0
0
1
0
0
1
0
0
1
0
0
0
输入
a0
0
1
0
1
BEGIN
PROCESS(oe,dir)
BEGINa1
IFoe='0'THENa<=”zzzzzzzz”;b<=”zzzzzzzz”;0
ELSIFoe='1'THEN0
IFdir='0'THENb<=a;1
ELSIFdir='1'THENa<=b;1
ENDIF;
ENDIF;
ENDPROCESS;
ENDar;
功能为:
2-4译码器..4分
2.请说明下段程序的功能,写出真值表,并画出输入输出波形。
LIBRARYieee;
USEieee.std_logic_1164.all;
USEieee.std_logic_arith.all;
USEieee.std_logic_unsigned.all;
ENTITYaaaIS
PORT(reset,clk:
INSTD_LOGIC;
q:
BUFFERSTD_LOGIC_VECTOR(2DOWNTO0));
ENDaaa;
ARCHITECTUREbdOFaaaIS
BEGIN
PROCESS(clk,reset)
BEGIN
IF(reset='0')THENq<="000";
ELSIF(clk'eventANDclk='1')THEN
IF(q=5)THENq<="000";
ELSEq<=q+1;
ENDIF;
ENDIF;
ENDPROCESS;ENDbd;
功能为:
带进位借位的4位加/减法器。
..3分
输入输出波形图如下:
m
a[3..O]1
X
X
X
…C-
X
X
X
)
b[3..U]
e[3..0],-
zxz
a
d
1.试用VHDL语言编程实现74LS273芯片的功能。
BEGIN
PROCESS(elk)
BEGIN
IF(CLR=''THENq<=”00000000”;
ELSEIF(elk'eventANDelk=''THENq<=d;
ELSEIF(elk=''THENq<=q;
ENDIF;
ENDPROCESS;
2'
1'
4'
1'
1'
2'
3'
1'
ENDIock8;
LIBRARY
ieee;
USE
ieee.std」ogie_1164.ALL;
2'
ENTITY
stasIS
1'
PORT(
ep,rst:
IN
std_logie;
p:
BUFFERstd_logie_veetor(7DOWNTO0);
2'
END
b
stas;
3•请用VHDL语言编程实现一个状态向量发生器。
ARCHITECTURE
arstas
OFstas
IS
1'
BEGIN
PROCESS(cp)
BEGIN
IF(rst=”O”THENp<=”00000000
1'
1'
1'
ELSEIF(cp'eventANDcp=''
ENDIF
ENDPROCESS;
ENDarstas;
1■阅读下段程序,画出该电路的真值表,并详细说明该电路的功能
LIBRARYIEEE;
USEIEEE.STD_LOGIC_1164.ALL;
USEIEEE.STD_LOGIC_UNSIGNED.ALL;
ENTITYab_8IS
PORT(a,b:
INSTD_LOGIC_VECTOR(7DOWNTO0);ahb,alb,aeb:
OUTSTD_LOGIC);
ENDab_8;
ARCHITECTUREbdOFab_8IS
ENDbd;
1.
(1)真值表如下:
(5')
输入
输出
a、b
ahb
alb
aeb
a>b
1
0
0
a
0
1
0
a=b
0
0
1
(2)该电路是一个8位两输入比较器,(2')
a、b是两个8位输入端;(1'
其余端输出为“0”(2'
ahb、alb和aeb为比较结果输出端,某种比较结果为真时,相应的输出端为"1”,
1■试用VHDL语言编程实现一个2-4译码器,其真表如下:
输入端
输出端
en
select
y
0
XX
1111”
1
00
1110”
1
01
1101”
1
10
1011”
1
11
0111”
2-4译码器码参考程序如下:
(答案不唯一,用case语句、with…select语句都可以。
)
LIBRARYIEEE;
USEIEEE.STD_LOGIC_1164.ALL;(1')
ENTITYym24IS
PORT(en:
INSTD_LOGIC;
select:
OUTSTD_LOGIC_VECTOR(1DOWNTO0);
y:
OUTSTD_LOGIC_VECTOR(3DOWNTO0)(3)
);
ENDym24;
ARCHITECTUREbdOFym24IS
BEGIN
PROCESS(en)
(1)
IF(en='1')THEN
y<=”1110”
WHEN
select="00”
ELSE
”1101”
WHEN
select=”01”
ELSE
”1011”
WHEN
select=”0”
ELSE
”0111”
WHEN
select=”1”
ELSE
(4'
AAA
1111;ELSEy<=”1111”;
ENDPROCESS;
ENDbd;
A、B、C、D、E、F都是8位输入总
2.试用VHDL语言设计一个六路8位总线复用器,其中线,Q为8位输出总线,S为3位选择端,其功能如下:
输入端
输出端
S2
S1
S0
Q7~Q0
0
0
0
Q=A
0
0
1
Q=B
0
1
0
Q=C
0
1
1
Q=D
1
0
0
Q=E
1
0
1
Q=F
其它
B=“00000000”
六路8位总线复用器参考程序:
(答案不唯一)
LIBRARYieee;
USEieee.std_logic_1164.ALL;
ENTITYmux6IS(1')
PORT(S:
INstd」ogic_vector(2DOWNTO0);
A,B,C,D,E,F:
INstd」ogic_vector(7DOWNTO0);
Q:
OUTstd」ogic_vector(7DOWNTO0)
);(3'
ENDmux6;
ARCHITECTUREbdOFmux6IS
BEGIN
PROCESS(S)
BEGIN(1')
CASESIS
WHEN"000"=>Q<=A;
WHEN"001"=>Q<=B;
WHEN"010"=>Q<=C;
WHEN"011"=>Q<=D;
WHEN"100"=>Q<=E;
WHEN"101"=>Q<=F;
WHENOTHERS=>Q<="00000000";(4')
ENDCASE;
ENDPROCESS;
ENDbd;
(10分)
2、已知三选一电路如图,判断下列程序是否有错误,如有则指出错误所在,并给出完整程序。
libraryieee;
useieee.std_logic_1164.all;
ENTITYMAXis
port(a1,a2,a3,s0,s1:
inbit;
outy:
outbit);
endmax;(2')
architectureoneofmaxis
componentmux21a
port(a,b,s:
instd_logic;
y:
outstd_logic);
endcomponent;(2')
signaltempstd_logic;_(2')
begin
u1:
mux21aportmap(a2,a3,s0,temp);(2')
u2:
mux21aportmap(a1,temp,s1,outy);
(2)
endone;
1.已知电路原理图如下,请用VHDL语言编写其程序
础肥:
答:
libraryieee;
useieee.std_logic_1164.all;
entitymux21is
port(a,b,s:
inbit;
y:
outbit);
endmux21;(4'
architectureoneofmux21is
singled,e:
bit;
begin
d<=aand(not)s;
e<=bands;
y<=dore;
endone;
2.设计一个带有异步清零功能的十进制计数器。
计数器时钟clk上升沿有效、清零端CLRN、进位输出
co。
COUNTER10
DQU"[
—
CLRN
co
—
答:
libraryieee;
useieee.std_logic_1164.all;
entitycounter10is
port(clk,CLRN:
instd_logic;
dout:
outintegerrange0to9);
endcounter10;(5'
architecturebehavofcounter10IS
begin
process(clk)
variablecnt:
integerrange0to9;(3'
begin
IFCLRN='0'THEN
CNT:
=0;
ELSIF
clk='1'andclk'eventthen
ifcnt=9then
cnt:
=O;
else
cnt:
=cnt+1;
endif;
endif;
dout<=cnt;
endprocess;
endbehav;
(7'
3.1)用VHDL语言编写半加器和或门器件的程序,如图所示:
OR"
RC
B
答:
半加器程序:
libraryieee;
useieee.std_logic_1164.all;
entityh_adderisport(a,b:
instd_logic;
co,so:
outstd_logic);
endh_adder;
architectureoneofh_adderisbegin
so<=not(axor(notb));
co<=aandb;
endone;
或门程序:
libraryieee;
useieee.std_logic_1164.all;
entityor2ais
port(a,b:
instd_logic;
c:
outstd_logic);
endor2a;
architectureoneofor2ais
begin
c<=aorb;
endone;
2)在上道题目的基础上用元件例化语句设计
(2'
(3')
1位全加器。
hi・i・Ii・ini■in■■■m■■ini・if
主程序:
libraryieee;
useieee.std_logic_1164.all;
entityf_adderis
port(ain,bin,cin:
instd_logic;
cout,sum:
outstd_logic);
endentityf_adder;
architecturefd1off_adderis
componenth_adderport(a,b:
instd_logic;
co,so:
outstd_logic);
endcomponent;
componentor2a
port(a,b:
instd_logic;
c:
outstd_logic);
endcomponent;
signald,e,f:
std_logic;
begin
u1:
h_adderportmap(a=>ain,b=>bin,co=>d,so=>e);u2:
h_adderportmap(a=>e,b=>cin,co=>f,so=>sum);u3:
or2aportmap(d,f,cout);
endfd1;
1.试用VHDL语言编程实现一个总线开关,其真值表如下:
输入
输出
en
select
A0~A6
B0~B6
Y0~Y6
0'
x
Zzzzzzz”
1'
0'
A
1'
1'
B
1.总线开关的参考程序如下:
LIBRARYieee;
USEieee.std_logic_1164.all;(1')
ENTITYaaaIS
PORT(en,select:
INSTD_LOGIC;
A,B:
INSTD_LOGIC_VECTOR(6DOWNTO0);
Y:
OUTSTD_LOGIC_VECTOR(6DOWNTO0)
ENDaaa;(4')
ARCHITECTUREarOFaaaIS
BEGIN
PROCESS(en,select)
BEGIN
IFen='0'THENY<=”ZZZZZZZ”;
ELSIFen='1'THEN
IFselect='0'THENY<=A;
ELSIFselect='1'THENY<=B;
ENDIF;
ENDIF;
ENDPROCESS;
ENDar;(5')
2.试用VHDL语言编程实现一个M10计数器,要求该计数器有一个时钟输入端clk,一个复位端
rst(低电平复位),一个使能端en(高电平时允许计数),一个“计数到”输出端cout,—个4位二进制
当前计数值输出口q;cout端仅当计数满的一个时钟周期输出高电平,其余时刻全保持低电平2.M10计数器参考程序:
LIBRARYieee;
USEieee.std_logic_1164.all;
1')
USEieee.std_logic_arith.all;
USEieee.std_logic_unsigned.all;
ENTITYaaaIS
PORT(clk,rst,en:
INSTD_LOGIC;cout:
OUTSTD_LOGIC;
q:
BUFFERSTD_LOGIC_VECTOR(3DOWNTO0));
ENDaaa;(4')
ARCHITECTUREbdOFaaaIS
BEGIN
PROCESS(clk,reset,en)
BEGIN
IF(rst='0')THENq<="0000";
ELSIF(clk'eventANDclk='1')THEN
IFen='1'THEN
IF(q=9)THENq<="0000";
ELSEq<=q+1;
ENDIF;
ENDIF;
ENDIF;
ENDPROCESS;
(10'
ENDbd;
3•请用VHDL语言编程,用一个状态机模型实现一个七段码LED字符发生器。
该电路有一个复位输入端RST,—个时钟输入端CP,—组七段码输出端a~g。
在LED上七个段的排列位置如图所示。
该电路的功能为,当复位输入端RST为低电平时,输出端口输出全零,无显示;当RST为高电平时,在时钟
3.
IFrst='0'THENpstate<=s0;
ELSIF(cp'eventANDcp='0')THEN
CASEpstateIS
WHENs0=>pstate<=s1;
WHENs1=>pstate<=s2;
WHENs2=>pstate<=s3;
WHENs3=>pstate<=s4;
WHENs4=>pstate<=s5;
WHENs5=>pstate<=s1;
WHENOTHERS=>pstate<=s0;
ENDCASE;
ENDIF;
ENDPROCESS;
pr2:
PROCESS(pstate)
BEGIN
CASEstateIS
WHENs0=>dout<="0000000";--无显示
WHENsi=>dout<="0110111";--H”
WHENs2=>dout<="1110111";--A”
WHENs3=>dout<="1100111";--P”
WHENs4=>dout<="1100111";--P”
WHENs5=>dout<="0111011";--Y”
WHENOTHERS=>dout<="0000000";--无显示
ENDCASE;
ENDPROCESS;(5'
a<=dout(6);b<=dout(5);c<=dout(4);d<=dout(3);e<=dout
(2);f<=dout
(1);g<=dout(0);
ENDaa;(1'
2.试用VHDL语言和进程语句,编程实现一个3-8译码器。
该译码器的功能为,当使能信号EN为低电平时,输出端丫7~丫0全为高电平(没有输出端被选中);当EN为高电平时,每一种ABC的输入状态组合能惟一地选中一路输出(被选中的端输出低电平)。
真值表如下:
输入
输出
A
B
C
EN
Y7
Y6
Y5
Y4
Y3
Y2
Y1
Y0
0
0
0
1
1
1
1
1
1
1
1
r0:
0
0
1
1
1
1
1
1
1
1
0
1
0
1
0
1
1
1
1
1
1
0
1
1
0
1
1
1
1
1
r11
1
0
1
1
r1
1
0
0
1
1
1
1
0
1
1
1
1
1
0
1
1
1
1
0
1
1
1
1
1
1
1
0
1
1
0
r1
1
1
1
1
r1
1
1
1
1
0
1
p厂
1
1
1
1
r1「
X
X
X
0
1
1
1
1
1
1
1
1
LIBRARYieee;
USE
ieee.std」ogic_1164.ALL;
2'
ENTITY
ym38IS
1'
PORT(
a,b,c,en:
IN
std_logic;
y:
OUT
std」ogic_vector(7DOWNTO0);
3'
END
丿;
ym38;
ARCHITECTUREarc38OF
ls273IS
1'
BEGIN
PROCESS(en)1
SIGNALdin:
std」ogic_vector(7DOWNTO0);1
BEGIN
di*=a&b&c&en;1
WITHdinSELECT
y<=”11111110'WHEN0001”;
”11111101”
WHEN
0011”;
”11111011”
WHEN
0101”;
”11110111”
WHEN
0111”;
”11101111”
WHEN
1001”;
”11011111”
WHEN
1011”;
”10111111”
WHEN
1101”;
”01111111”
WHEN
1111”;
”11111111”
WHEN
OTHERS
ENDPROCESS;
ENDarc38;
1.试用VHDL语言编程实现一个多路开关。
该电路的功能为,当选择端So和Si为不同状态组合时,如果使能信号EN为电平,输出端X和Y分别与不同的输入通道AoBo、A1B1、A2B2和A3B3接通并保持,当EN为低电平时,X、Y输出为高阻态。
真值表如下:
输入
输出
S1
S0
EN
A0
B0
A1
B1
A2
B2
A3
B3
X
Y
0
01
1
X
X
X
X
X
X
X
X
A0
B01
0
1
1
X
X
X
X
X
X
X
X
A1
B1
1
0
1
X
X
X
X
X
X
X
X
A2
B2I
1
11
1
X
X
X
X
X
X
X
X
A3
B3:
X
X
0
X
X
X
X
X
X
X
X
Z
Z
1.多路开关的参考程序如下:
LIBRARYieee;
2'
USEieee.std」ogic_1164.ALL;
PORT(
s0,s1,en,a0,b0,a1,b1,a2,b2,a3,b3:
INstd_logic;
x,y:
);
OUTstd」ogic_vector(7DOWNTO0);
3
END
mulkey;
丿;
architecture
armk
OFmulkeyIS
signal
BEGIN
sel:
std_logic_vecter(1DOWNTO0)
ENTITYmulkeyIS
sel<=s1&s0;
PROCESS(en)
BEGIN
IF(en='0')THENx<=
y<='Z'
ELSEIF(sel=”00”)THEN
x<=a0;
y<=b0;
ELSEIF(sel=”01”)THEN
x<=a1;
y<=b1;
ELSEIF(sel=”10”)THEN
x<=a2;
y<=b2;
ELSEIF