上机练习的实验VHDLWord下载.docx
《上机练习的实验VHDLWord下载.docx》由会员分享,可在线阅读,更多相关《上机练习的实验VHDLWord下载.docx(18页珍藏版)》请在冰点文库上搜索。
endif;
cnt_temp<
=conv_std_logic_vector(tmp,5);
endprocess;
q0<
=cnt_temp(0);
q1<
=cnt_temp
(1);
q2<
=cnt_temp
(2);
q3<
=cnt_temp(3);
q4<
=cnt_temp(4);
cnt<
=cnt_temp;
endarchitecturertl;
2.CNT_10用VHDL实现十进制计数器。
entitycnt_10is
port(rst_n:
cnt_o:
outintegerrange0to9);
endentitycnt_10;
architecturertlofcnt_10is
integerrange0to9;
elsifclk'
iftmp=9then
cnt_o<
=tmp;
3.fre_div1.用VHDL设计一个电路可以实现2分频,4分频,8分频功能的电路。
entityfre_divis
b0:
b1:
b2:
b3:
outstd_logic);
endentityfre_div;
architecturertloffre_divis
signaltmp:
std_logic_vector(3downto0);
process(rst_n,clk)
tmp<
="
0000"
;
iftmp="
1111"
b0<
=tmp(0);
b1<
=tmp
(1);
b2<
=tmp
(2);
b3<
=tmp(3);
endrtl;
4.DIV_6用VHDL状态机设计6分频电路。
libraryieee;
entitydiv_6is
q_com:
q:
endentitydiv_6;
architecturertlofdiv_6is
typestate_tis(s_rst,s0,s1,s2,s3,s4,s5);
signalstate,next_state:
state_t;
signalq_tem:
std_logic;
begin
process(clk,rst_n)
state<
=s_rst;
=next_state;
process(state)
casestateis
whens_rst=>
next_state<
=s0;
whens0=>
=s1;
whens1=>
=s2;
whens2=>
=s3;
whens3=>
=s4;
whens4=>
=s5;
whens5=>
endcase;
q_tem<
='
process(clk)
q<
=q_tem;
q_com<
5.FRE_DIV_10用VHDL实现十分频电路设计,要求输出信号占空比为一半
entityfre_div_10is
endentityfre_div_10;
architecturertloffre_div_10is
signalq_o:
process(rst_n,clk)is
variabletem:
integerrange0to4;
tem:
iftem=4then
=tem+1;
process(rst_n,q_tem)is
q_o<
elsifq_tem'
eventandq_tem='
=not(q_o);
=q_o;
6.SER_2PER用VHDL语言设计一个串并转换电路,输入一位数据,输出八位数据,当一组八位并行数据转换结束时,输出使能信号有效八位数据输出在转换期间,输出时能信号无效,输出为高阻。
entityser_2paris
port
(rst_n:
din:
dout:
outstd_logic_vector(7downto0));
endentityser_2par;
architecturertlofser_2paris
signaloe:
std_logic;
signaltemp:
std_logic_vector(7downto0);
variablecnt:
integerrange0to7;
oe<
ifcnt=7then
;
=cnt+1;
temp<
=(others=>
'
);
temp(0)<
=din;
foriin0to6loop
temp(i+1)<
=temp(i);
endloop;
process(oe,temp)
ifoe='
dout<
=temp;
Z'
7.SHIFT_82.信号和变量的使用
注意区别。
验证例8-37并修改信号为变量,观察仿真结果的差别
例8-378位移步寄存器直接利用信号来连接
entityshift_8is
port(a,clk:
b:
endentityshift_8;
architecturertlofshift_8is
signaldfo_1,dfo_2,dfo_3,dfo_4,dfo_5,dfo_6,dfo_7,dfo_8:
process(clk)is
if(clk'
)then
dfo_1<
=a;
dfo_2<
=dfo_1;
dfo_3<
=dfo_2;
dfo_4<
=dfo_3;
dfo_5<
=dfo_4;
dfo_6<
=dfo_5;
dfo_7<
=dfo_6;
dfo_8<
=dfo_7;
b<
=dfo_8;
endif;
endprocess;
endarchitecturertl;
例8-378位移步寄存器用变量的连接描述
port(a,clk:
process(clk)is
variabledfo_1,dfo_2,dfo_3,dfo_4,dfo_5,dfo_6,dfo_7,dfo_8:
dfo_1:
dfo_2:
dfo_3:
dfo_4:
dfo_5:
dfo_6:
dfo_7:
dfo_8:
b<
8.sign_add3.设计9位2进制有符号数加法器,8位输入数据,不考虑进位输入,8位输出数据,1位进位输出,验证结果。
(可使用运算操作符)
entitysign_addis
port(a:
instd_logic_vector(7downto0);
so:
outstd_logic_vector(8downto0);
s:
outstd_logic_vector(7downto0);
co:
endentitysign_add;
architecturertlofsign_addis
signalatmp,btmp,tmp:
std_logic_vector(8downto0);
atmp<
=a(7)&
a;
btmp<
=b(7)&
b;
=atmp+btmp;
s<
=tmp(7downto0);
co<
=tmp(8);
so<
9.ZERO_TEST用VHDL设计零检测电路,要求可以检测六位任意二进制数据中零的个数。
entityzero_testis
port(d_in:
instd_logic_vector(15downto0);
zero_cnt:
outintegerrange0to16);
endentityzero_test;
architecturertlofzero_testis
process(d_in)
integerrange0to16;
foriind_in'
rangeloop
--foriin15downto0loop
cased_in(i)is
when'
=>
whenothers=>
=cnt;
--exit;
zero_cnt<
10.比较器2.设计8位2进制比较器,若A>
B,Y输出为1,若A<
=B,Y输出为0
entitybijiao_1is
port(a,b:
instd_logic_vector(7downto0);
y:
outstd_logic);
endentitybijiao_1;
architecturertlofbijiao_1is
process(a,b)is
if(a>
b)then
y<
elsey<
11.构造体结构化描述练习
例8-15,要把例8-14放在同一个工程里面
采用名称映射法修改端口映射方式。
例8-14
entityhalf_adderis
s,co:
endentityhalf_adder;
architecturehalf1ofhalf_adderis
signalc,d:
begin
c<
=aorb;
d<
=anandb;
=notd;
=candd;
endarchitecturehalf1;
例8-15
entityfull_adderis
port(a,b,cin:
endentityfull_adder;
architecturefull_adderis
endcomponent;
signalu0_co,u0_s,u1_co:
u0:
half_adderportmap(a>
=u0_s,b>
=u0_co,s>
=u0_s,co>
=u0_co);
u1:
=s,co>
=u1_co);
co<
=u0_cooru1_co;
endarchitecturefull;
12.采用进程描述例8-1
要求:
(1)采用敏感信号列表
(2)采用wait语句
(1)libraryieee;
entitynand_2is
port(a,b:
y:
endentitynand_2;
architecturenand_2_1ofnand_2is
process(a,b)is
y<
endarchitecturenand_2_1;
(2)libraryieee;
process
=aandb;
waitona,b;