版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
第5章基于HDL的时序逻辑电路实验5.1边沿D触发器实验5.2计数器实验5.3寄存器和移位寄存器实验5.4串行序列检测器设计
数字电路分为组合逻辑电路和时序逻辑电路。组合逻辑电路任何时刻输出信号的逻辑状态仅取决于该时刻输入信号的逻辑状态,电路中不包含记忆性电路或器件。时序逻辑电路的输出状态不仅与该时刻的输入有关,而且还与电路历史状态有关。时序逻辑电路的基本单元是触发器,具有记忆输入信息的功能。
5.1边沿D触发器实验
通过使用ISE软件和FPGA实现实验图5-1所示的带有置位和清零端的边沿D触发器的逻辑图。在ISE上仿真并在实验开发板上实现,通过开发板上的SW7改变D的状态,观察触发器输出变化,说明为什么输出q会随着D变化,并用D触发器设计一个2分频计数器,通过两个LED显示分频前后的信号。部分实验参考内容见后。图5-1维持阻塞型D触发器
(1)实现图5-1所示的边沿D触发器的VerilogHDL参考源代码如下:
moduleflipflopcs(
inputwireclk,
inputwireD,
inputwireset,
inputwireclr,
outputq,
outputnotq
);
wiref1,f2,f3,f4,f5,f6;
assign#5f1=~(f4&f2&~set);//#5表示与门加5个单位时间的传输延时
assign#5f2=~(f1&f5&~clr);
assign#5f3=~(f6&f4&~set);
assign#5f4=~(f3&clk&~clr);
assign#5f5=~(f4&clk&f6&~set);
assign#5f6=~(f5&D&~clr);
assignq=f1;
assignnotq=f2;
endmodule
//以下是带清零端的DFF
moduleDff(
inputwireclk,
inputwireclr,
inputwireen,
inputwireD,
outputregq
);
always@(posedgeclkorposedgeclr)
begin
if(clr)q<=0;
elseif(en)q<=D;
end
endmodule
使用ISESimulator,VerilogHDL参考源代码的仿真结果如图5-2所示。
由图5-2可见,电路开始工作时,如果set和clr信号为低电平无效,且clk无有效上沿时,触发器的输出q和notq是不确定的x(图中的非0非1线),当第一个clk上沿到来时,D触发器的输出状态变化(D为1,则输出q为1)。同时,由图可见门电路的延时。图5-2边沿D触发器的仿真结果
(2)边沿D触发器的VHDL源代码如下:
--BehavioralDFlip-FlopwithClockEnableandAsynchronousReset
entityDflipflopis
Port(D,clk,rst,ce:inSTD_LOGIC;
Q:outSTD_LOGIC);
endDflipflop;
architectureBehavioralofDflipflopis
begin
process(clk,rst,D,ce)
begin
ifrst=‘1’thenQ<=‘0’;
elseif(clk‘eventandclk=’1‘)
thenifce=’1‘thenQ<=D;
endif;
endif;
endprocess;
endBehavioral;
--BehavioralDFlip-Flop,SynchronousReset
entityDFFis
Port(D,clk,rst:inSTD_LOGIC;
Q:outSTD_LOGIC);
endDFF;
architectureBehavioralofDFFis
begin
process(clk,rst,D)
begin
if(CLK'eventandCLK='1')then
ifrst='1'thenQ<='0';
elseQ<=D;
endif;
endif;
endprocess;
endBehavioral;
--Behavioral8bitDRegisterwithAsynchronousReset
entityReg8is
port(D:inSTD_LOGIC_VECTOR(7downto0);
clk,rst:inSTD_LOGIC;
Q:outSTD_LOGIC_VECTOR(7downto0));
endReg8;
architectureBehavioralofReg8is
begin
process(clk,rst)
begin
ifrst='1'thenQ<="00000000";
elsif(CLK'eventandCLK='1')thenQ<=D;
endif;
endprocess;
endBehavioral;
(3)带有置位和清零端的边沿D触发器的约束文件规定如下:
#Basys2约束文件:
NET"clk"LOC="B8";//时钟
NET"D"LOC="N3";//SW7
NET"set"LOC="L3";//SW1
NET"clr"LOC="P11";//SW0
NET"q"LOC="G1"; //LD7
NET"notq"LOC="P4";//LD6
#Basys2约束文件:
NET"clk"LOC="B8";//时钟
NET"D"LOC="N3";//SW7
NET"set"LOC="L3";//SW1
NET"clr"LOC="P11";//SW0
NET"q"LOC="G1"; //LD7
NET"notq"LOC="P4";//LD6
5.2计 数 器 实 验
5.2.1计数器简介
计数器是一种最常用的时序逻辑电路,通常有加、减和可逆三种计数方式,计数器的模多数为2n进制或十进制。一般都有使能控制端,当控制信号有效时,一个N进制计数器在有效时钟Clk边沿作用下,按照计数方式改变次态。当计数到最后一个状态Sn-1时,一般会产生进位或/和借位信号,如图5-3中的TC(TerminalCount),表示最后一个计数状态,在下一个有效时钟边沿,状态回到初始状态S0。2n进制的计数器每个输出都是时钟信号Clk的分频,且占空比为50%,如图5-3和图5-4所示。图5-3二进制计数器及波形图图5-42n进制计数器5.2.2计数器实验和预习内容
(1)学习VHDL的读者分析以下代码功能。
libraryIEEE;
useIEEE.STD_LOGIC_1164.all;
useIEEE.STD_LOGIC_ARITH.all;
useIEEE.STD_LOGIC_UNSIGNED.all;
entitycounteris
Port(clk:inSTD_LOGIC;
rst:inSTD_LOGIC;
B:inoutSTD_LOGIC_VECTOR(3downto0));
endcounter;
architectureBehavioralofcounteris
begin
process(clk,rst)
begin
if(rst='1')then
B<="0000";
elseif(clk'eventandclk='1')then
B<=B+1;
endif;
endproess;
endBehavioral;
--将50MHz时钟分频为1Hz的代码如下,常数是分频数,可以根据分频需要改变。
libraryIEEE;
useIEEE.STD_LOGIC_1164.all;
useIEEE.STD_LOGIC_ARITH.all;
useIEEE.STD_LOGIC_UNSIGNED.all;
entityclkdivis
Port(clk:inSTD_LOGIC;
rst:inSTD_LOGIC;
clkout:outSTD_LOGIC);
endclkdiv;
architectureBehavioralofclkdivis
constantcntendval:STD_LOGIC_VECTOR(25downto0):="10111110101111000010000000";
signalcntval:STD_LOGIC_VECTOR(25downto0);
begin
process(clk,rst)
begin
if(rst='1')then
cntval<="00000000000000000000000000";
elsif(clk'eventandclk='1')then
if(cntval=cntendval)then
cntval<="00000000000000000000000000";
elsecntval<=cntval+1;
endif;
endif;
endprocess;
clkout<=cntval(25);
endBehavioral;仿真并在开发板上验证以下设计(用1s的时钟接clk可以看到结果,BASYS2板上clk接C8)。
LIBRARYIEEE;
USEIEEE.STD_LOGIC_1164.ALL;
USEIEEE.STD_LOGIC_UNSIGNED.ALL;
ENTITYCNT4BIS
PORT(CLK:INSTD_LOGIC;
RST:INSTD_LOGIC;
ENA:INSTD_LOGIC;
OUTY:OUTSTD_LOGIC_VECTOR(3DOWNTO0);
COUT:OUTSTD_LOGIC);
ENDCNT4B;
ARCHITECTUREbehavOFCNT4BIS
SIGNALCQI:STD_LOGIC_VECTOR(3DOWNTO0);
BEGIN
P_REG:PROCESS(CLK,RST,ENA,CQI)
BEGIN
IFRST='1'THENCQI<="0000";
ELSIFCLK'EVENTANDCLK='1'THEN
IFENA='1'THENCQI<=CQI+1;
ENDIF;
ENDIF;
OUTY<=CQI;
ENDPROCESSP_REG;--进位输出
COUT<=CQI(0)ANDCQI(1)ANDCQI(2)ANDCQI(3);
ENDbehav;
(2)使用ISE软件和FPGA实现模6计数器,即计数状态从000依次加1到101状态,下一次有效触发沿到来时再回到000状态。仿真并在开发板上验证其计数功能。
modulemod6cnt(
inputwireclr,
inputwireclk,
outputreg[2:0]q
);
reg[24:0]q1;
//25位计数器,对50MHz时钟进行225分频
always@(posedgeclkorposedgeclr)
begin
if(clr==1)
q1<=0;
else
q1<=q1+1;
end
assignmclk=q1[24];//1.5Hz
//模6计数器
always@(posedgemclkorposedgeclr)
begin
if(clr==1)
q<=0;
elseif(q==5)
q<=0;
else
q<=q+1;
end
endmodule
建立上述代码的VerilogTestFixture仿真文件,在文件模板中添加以下激励代码:
//Addstimulushere
#100;clr<=1;clk<=0;
#100;clr<=1;clk<=1;
#100;clr<=0;clk<=0;
#100;clr<=0;clk<=1;
#100;clr<=0;clk<=0;
#100;clr<=0;clk<=1;
#100;clr<=0;clk<=0;
#100;clr<=0;clk<=1;
#100;clr<=0;clk<=0;
#100;clr<=0;clk<=1;
#100;clr<=0;clk<=0;
#100;clr<=0;clk<=1;
#100;clr<=0;clk<=0;
#100;clr<=0;clk<=1;
#100;clr<=1;clk<=0;
#100;clr<=1;clk<=1;仿真结果如图5-5所示,由图可见clr清0无效,而且在出现clk有效上沿后计数器的计数值q[2:0]始终为000,分析原因。图5-5模6计数器仿真结果模6计数器的VHDL程序:
entitymod6cntis
Port(clr:inSTD_LOGIC;
clk:inSTD_LOGIC;
q:inoutSTD_LOGIC_VECTOR(2downto0));
endmod6cnt;
architectureBehavioralofmod6cntis
signalq1:std_logic_vector(24downto0);
signalmclk:std_logic;
begin
process(clr,clk)
begin
if(clr='1')then
q1<="0000000000000000000000000";
elsif(clk'eventandclk='1')then
q1<=q1+1;
endif;
endprocess;
mclk<=q1(24);
process(mclk,clr,q)
begin
if(clr='1')then
q<="000";
elsif(q="110")then
q<="000";
elsif(mclk'eventandmclk='1')then
q<=q+1;
endif;
endprocess;
endBehavioral;在开发板上验证模6计数器的约束文件规定如下,观察结果是否正确。
#Basys2约束文件:
NET"clk"LOC="B8";//时钟
NET"clr"LOC="P11";//SW0
NET"q[2]"LOC="G1";//LD7
NET"q[1]"LOC="P4";//LD6
NET"q[0]"LOC="N4";//LD5
#Basys2约束文件:
NET"clk"LOC="B8";//时钟
NET"clr"LOC="P11";//SW0
NET"q[2]"LOC="G1";//LD7
NET"q[1]"LOC="P4";//LD6
NET"q[0]"LOC="N4";//LD5在实现上述工程文件之后,Place&Route中出现以下WARNING信息,查找资料说明是什么问题。
WARNING:Route:455-CLKNet:q1<24>mayhaveexcessiveskewbecause
但WARNING并不影响设计文件的功能,将上述工程产生的代码下载到开发板,在开发板的LD7~LD5可以看到计数循环是由000B依次加1到101B的6进制计数状态。
(3)在上述实验基础上,设计一个秒脉冲发生器,用LED指示秒脉冲的发生。
5.3寄存器和移位寄存器实验
寄存器是数字系统中用来存储二进制数据的逻辑器件,在数字系统中广泛使用。当然,每个触发器都可以寄存一位二进制数,但寄存器一般是指可以存储多位二进制数的逻辑电路或器件。寄存器内部包含多个触发器,待保存的数据在外部时钟脉冲统一控制下存入触发器中。如果触发器的输出经三态门接到寄存器的引脚,则寄存器为三态输出。寄存器电路按逻辑功能可分为并行寄存器、串行寄存器和串并行寄存器。并行寄存器是指其输入输出都是并行的,没有移位功能,通常简称为寄存器。串行寄存器具有移位功能,因此也称为移位寄存器。5.3.1寄存器实验和预习内容
(1)根据所学的HDL语言,分析下面的程序代码中各个参数含义以及实现的逻辑功能,并对代码进行仿真验证。
moduleregister
#(parameterN=8)
(inputwireload,
inputwireclk,
inputwireclr,
inputwire[N-1:0]d,
outputreg[N-1:0]q
);
always@(posedgeclkorposedgeclr)
if(clr==1)
q<=0;
elseif(load==1)
q<=d;
endmodule
LibraryIEEE
useIEEE.std_logic_1164.all
entityreg12is
PORT(
d:INSTDLOGICVECTOR(11DOWNTO0);
clk:INSTDLOGIC;
q:OUTSTDLOGIC_VECTOR(11DOWNTO0));
endreg12;
architectureBehavioralofreg12is
begin
ifclk'eventandclk='1'then
q<=d;
endif;
ENDPROCESS;
endBehavioral;
(2)试设计一个带有异步清零和置数信号(置数为全逻辑1)的4位寄存器,并在开发板上验证。5.3.2移位寄存器实验和预习内容
(1)使用ISE软件和FPGA分别实现图5-6所示的4位移位寄存器功能。
图5-6的Verilog设计参考源代码如下,在开发板上验证该功能。学习VHDL的读者分析下面的VHDL代码完成什么功能。修改代码完成图5-6的功能。图5-64位移位寄存器
moduleShiftReg(
inputwireclk,
inputwireclr,
inputwiredata_in,
outputreg[3:0]q
);
reg[24:0]q1;
//25位计数器进行分频
always@(posedgeclkorposedgeclr)
begin
if(clr==1)
q1<=0;
else
q1<=q1+1;
end
assignmclk=q1[24];//1.5Hz
//4位移位寄存器
always@(posedgemclkorposedgeclr)
begin
if(clr==1)
q<=0;
else
begin
q[3]<=data_in;
q[2:0]<=q[3:1];
end
end
endmodule
libraryieee;
useieee.std_logic_1164.all;
useieee.std_logic_arith.all;
useieee.std_logic_unsigned.all;
entityShiftRegis
port( data:instd_logic_vector(3downto0);
left_da,right_da,reset,clk:instd_logic;
mode:instd_logic_vector(1downto0);
qout:bufferstd_logic_vector(3downto0));
endShiftReg;
architecturebehaveofShiftRegis
begin
process
begin
waituntilrising_edge(clk);
if(reset='1')then
qout<="0000";
else
casemodeis
when"01"=qout<=right_da&qout(3downto1);
when"10"=>qout<=qout(2downto0)&left_da;
when"11"=>qout<=data;
whenothers=>null;
endcase;
endif;
endprocess;
endbehave;建立Verilog代码的仿真文件,在文件模板中加入以下激励代码:
//Addstimulushere
#100;clr<=1;data_in<=1;clk<=0;
#100;clr<=1;data_in<=1;clk<=1;
#100;clr<=0;data_in<=1;clk<=0;
#100;clr<=0;data_in<=1;clk<=1;
#100;clr<=0;data_in<=1;clk<=0;
#100;clr<=0;data_in<=1;clk<=1;
#100;clr<=0;data_in<=1;clk<=0;
#100;clr<=0;data_in<=1;clk<=1;
#100;clr<=0;data_in<=1;clk<=0;
#100;clr<=0;data_in<=1;clk<=1;
#100;clr<=1;data_in<=1;clk<=0;图5-7是Verilog代码实现的图5-6的功能仿真图,由图可见clr的高电平异步清0作用和数据移位功能。图5-7图5-6所示移位寄存器仿真图移位寄存器的VHDL设计参考源代码如下:
libraryieee;
useieee.std_logic_1164.all;
useieee.std_logic_arith.all;
useieee.std_logic_unsigned.all;
entityShiftRegis
port(data:instd_logic_vector(3downto0);
left_da,right_da,reset,clk:instd_logic;
mode:instd_logic_vector(1downto0);
qout:bufferstd_logic_vector(3downto0));
endShiftReg;
architecturebehaveofShiftRegis
begin
process
begin
waituntilrising_edge(clk);
if(reset='1')then
qout<="0000";
else
casemodeis
when"01"=>qout<=right_da&qout(3downto1);
when"10"=>qout<=qout(2downto0)&left_da;
when"11"=>qout<=data;
whenothers=>null;
endcase;
endif;
endprocess;
endbehave;
如果约束文件规定如下,程序下载到开发板。当clr为高电平寄存器清0,LD7~LD4熄灭,当clr为低电平,SW7拨上为高电平,则可见LD7到LD4依次点亮,SW7为0,则依次熄灭。说明移位的正确性。#Basys2约束文件:
NET"clk"LOC="B8";
NET"data_in"LOC="N3";//SW7
NET"clr"LOC="P11"; //SW0
NET"q[3]"LOC="G1";//LD7
NET"q[2]"LOC="P4";//LD6
NET"q[1]"LOC="N4";//LD5
NET"q[0]"LOC="N5";//LD4#Basys2约束文件:
NET"clk"LOC="B8";
NET"data_in"LOC="N3";//SW7
NET"clr"LOC="P11"; //SW0
NET"q[3]"LOC="G1";//LD7
NET"q[2]"LOC="P4";//LD6
NET"q[1]"LOC="N4";//LD5
NET"q[0]"LOC="N5";//LD4
(2)图5-8所示的4位移位器是在算术运算单元(ALU)中用到的多种逻辑或算术移位。用HDL描述电路功能,给出仿真波形,并在开发板上验证。
图5-8的VerilogHDL参考代码如下:
moduleshift4(
inputwire[3:0]d,
inputwire[2:0]s,
outputreg[3:0]y
);
always@(*)
case(s)
0:y=d; //noshift
1:y={1'b0,d[3:1]}; //shr
2:y={d[2:0],1'b0}; //shl
3:y={d[0],d[3:1]}; //ror
4:y={d[2:0],d[3]}; //rol
5:y={d[3],d[3:1]}; //asr
6:y={d[1:0],d[3:2]}; //ror2
7:y=d; //noshift
default:y=d;
endcase
endmodule图5-8多种逻辑或算术移位图5-8的VHDL程序如下:
entityshift4is
Port(d:inSTD_LOGIC_VECTOR(3downto0);
s:inSTD_LOGIC_VECTOR(2downto0);
y:outSTD_LOGIC_VECTOR(3downto0));
endshift4;
architectureBehavioralofshift4is
begin
process(d,s)
begin
casesis
when“000”=>y<=d;
when"001"=>y<='0'&d(3downto1);
when"010"=>y<=d(2downto0)&'0';
when"011"=>y<=d(0)&d(3downto1);
when"100"=>y<=d(2downto0)&d(3);
when"101"=>y<=d(3)&d(3downto1);
when"110"=>y<=d(1downto0)&d(3downto2);
whenothers=>null;
endcase;
endprocess;
endBehavioral;5.3.3寄存器和简单外设综合实验
使用ISE软件和FPGA设计一个可以把4个SW开关的内容存储到一个4位寄存器的电路,并在开发板的最右边的七段显示管上显示这个寄存器中的十六进制数字。设计顶层原理图如图5-9所示。分频模块clkdiv用以产生模块clock_pulse和x7segbc的时钟信号clk190(该模块输入mclk为50MHz,输出为190Hz);clock_pulse为按键去抖动模块,btn[0]是clock_pulse输入信号;寄存器模块register用btn[1]作为加载信号load;x7segbc为七段数码管的译码和控制模块。图5-9设计顶层原理图图5-9的VerilogHDL参考设计源代码如下:
//顶层设计:
modulesw2regtop(
inputwiremclk,
inputwireclr,
inputwire[1:0]btn,
inputwire[3:0]sw,
outputwire[3:0]ld,
outputwire[6:0]a_to_g,
outputwire[3:0]an,
outputwiredp
);
wire[3:0]q;
wireclk190,clkp;
wire[3:0]x;
assignx=q;
assignld=sw;
clkdivU1(.mclk(mclk),
.clr(clr),
.clk190(clk190)
);
clock_pulseU2(.inp(btn[0]),
.cclk(clk190),
.clr(clr),
.outp(clkp)
);
register#(.N(4))
U3(.load(btn[1]),
.clk(clkp),
.clr(clr),
.d(sw),
.q(q)
);
x7segbcU4(.x(x),
.a_to_g(a_to_g),
.an(an),
.dp(dp)
);
endmodule
//分频模块:
moduleclkdiv(
inputwiremclk,
inputwireclr,
outputwireclk190
);
reg[17:0]q;
//18位计数器
always@(posedgemclkorposedgeclr)
begin
if(clr==1)
q<=0;
else
q<=q+1;
end
assignclk190=q[17];//190Hz
endmodule
//去抖动模块:
moduleclock_pulse(
inputwireinp,
inputwirecclk,
inputwireclr,
outputwireoutp
);
regdelay1;
regdelay2;
regdelay3;
always@(posedgecclkorposedgeclr)
begin
if(clr==1)
begin
delay1<=0;
delay2<=0;
delay3<=0;
end
else
begin
delay1<=inp;
delay2<=delay1;
delay3<=delay2;
end
end
assignoutp=delay1&delay2&~delay3;
endmodule
//寄存器模块:
moduleregister
#(parameterN=4)
(inputwireload,
inputwireclk,
inputwireclr,
inputwire[N-1:0]d,
outputreg[N-1:0]q
);
always@(posedgeclkorposedgeclr)
if(clr==1)
q<=0;
elseif(load==1)
q<=d;
endmodule
//七段数码管译码和控制模块(输入时钟信号cclk应为190Hz):
modulex7segbc(
inputwire[3:0]x,
outputreg[6:0]a_to_g,
outputwire[3:0]an,
outputwiredp
);
assigndp=1; //小数点不显示
assignan=4'b1110; //使能最右边的数码管
//七段解码器:hex7seg
always@(*)
case(x)
0:a_to_g=7'b0000001;
1:a_to_g=7'b1001111;
2:a_to_g=7'b0010010;
3:a_to_g=7'b0000110;
4:a_to_g=7'b1001100;
5:a_to_g=7'b0100100;
6:a_to_g=7'b0100000;
7:a_to_g=7'b0001111;
8:a_to_g=7'b0000000;
9:a_to_g=7'b0000100;
'hA:a_to_g=7'b0001000;
'hB:a_to_g=7'b1100000;
'hC:a_to_g=7'b0110001;
'hD:a_to_g=7'b1000010;
'hE:a_to_g=7'b0110000;
'hF:a_to_g=7'b0111000;
default:a_to_g=7'b0000001;//0
endcase
endmodule图5-9的VHDL参考设计源代码如下:
顶层程序如下:
entitysw2regtopis
Port(mclk:instd_logic;
clr:instd_logic;
btn:instd_logic_vector(1downto0);
sw:instd_logic_vector(3downto0);
ld1:outstd_logic_vector(3downto0);
a_to_g:outstd_logic_vector(6downto0);
an:outstd_logic_vector(3downto0);
dp:outstd_logic
);
endsw2regtop;
architectureBehavioralofsw2regtopis
componentclkdivis
Port(mclk:inSTD_LOGIC;
clr:inSTD_LOGIC;
clk190:outSTD_LOGIC);
endcomponent;
componentclock_pulseis
Port(inp:inSTD_LOGIC;
cclk:inSTD_LOGIC;
clr:inSTD_LOGIC;
outp:outSTD_LOGIC);
endcomponent;
componentx7segbcis
Port(x:inSTD_LOGIC_VECTOR(3downto0);
a_to_g:outSTD_LOGIC_VECTOR(6downto0);
an:outSTD_LOGIC_VECTOR(3downto0);
dp:outSTD_LOGIC);
endcomponent;
componentregis
Port(load:inSTD_LOGIC;
clk:inSTD_LOGIC;
clr:inSTD_LOGIC;
d:inSTD_LOGIC_VECTOR(3downto0);
q:outSTD_LOGIC_VECTOR(3downto0));
endcomponent;
signalclk190,clkp:STD_LOGIC;
--signalx:std_logic_vector(3downto0);
signalq:std_logic_vector(3downto0);
begin
--x<=q;
ld1<=sw;
c_div:clkdiv
portmap(mclk,clr,clk190);
c_pulse:clock_pulse
portmap(btn(0),clk190,clr,clkp);
c_reg:reg
portmap(btn(1),clkp,clr,sw,q);
c_dis:x7segbc
portmap(q,a_to_g,an,dp);
endBehavioral;
//分频模块:
entityclkdivis
Port(mclk:inSTD_LOGIC;
clr:inSTD_LOGIC;
clk190:outSTD_LOGIC);
endclkdiv;
architectureBehavioralofclkdivis
signalq:std_logic_vector(17downto0);
begin
process(mclk,clr)
begin
if(clr='1')then
q<="000000000000000000";
elsif(mclk'eventandmclk='1')then
q<=q+1;
endif;
endprocess;
clk190<=q(17);
endBehavioral;
//去抖动模块:
entityclock_pulseis
Port(inp:inSTD_LOGIC;
cclk:inSTD_LOGIC;
clr:inSTD_LOGIC;
outp:outSTD_LOGIC);
endclock_pulse;
architectureBehavioralofclock_pulseis
signaldelay1:std_logic;
signaldelay2:std_logic;
signaldelay3:std_logic;
begin
process(clr,cclk,inp)
begin
if(clr='1')then
delay1<='0';
delay2<='0';
delay3<='0';
elsif(cclk'eventandcclk='1')then
delay1<=inp;
delay2<=delay1;
delay3<=delay2;
endif;
endprocess;
outp<=delay1anddelay2and(notdelay3);
endBehavioral;
//寄存器模块:
entityregis
Port(load:inSTD_LOGIC;
clk:inSTD_LOGIC;
clr:inSTD_LOGIC;
d:inSTD_LOGIC_VECTOR(3downto0);
q:outSTD_LOGIC_VECTOR(3downto0));
endreg;
architectureBehavioralofregis
begin
process(clk,load,clr,d)
begin
if(clr='1')then
q<="0000";
elsif(clk'eventandclk='1')then
if(load='1')then
q<=d;
endif;
endif;
endprocess;
endBehavioral;
//7段数码管译码和控制模块(输入时钟信号cclk应为190Hz):
libraryIEEE;
useIEEE.STD_LOGIC_1164.ALL;
--Uncommentthefollowinglibrarydeclarationifusing
--arithmeticfunctionswithSignedorUnsignedvalues
--useIEEE.NUMERIC_STD.ALL;
--Uncommentthefollowinglibrarydeclarationifinstantiating
--anyXilinxprimitivesinthiscode.
--libraryUNISIM;
--useUNISIM.VComponents.all;
entityx7segbcis
Port(x:inSTD_LOGIC_VECTOR(3downto0);
a_to_g:outSTD_LOGIC_VECTOR(6downto0);
an:outSTD_LOGIC_VECTOR(3downto0);
dp:outSTD_LOGIC);
endx7segbc;
architectureBehavioralofx7segbcis
begin
an<="1110";
dp<='1';
process(x)
begin
casexis
when"0000"=>a_to_g<="0000001";
when"0001"=>a_to_g<="1001111";
when"0010"=>a_to_g<="0010010";
when"0011"=>a_to_g<="0000110";
when"0100"=>a_to_g<="1001100";
when"0101"=>a_to_g<="0100100";
when"0110"=>a_to_g<="0100000";
when"0111"=>a_to_g<="0001111";
when"1000"=>a_to_g<="0000000";
when"1001"=>a_to_g<="0000100";
when"1010"=>a_to_g<="0001000";
when"1011"=>a_to_g<="1100001";
when"1100"=>a_to_g<="0110001";
when"1101"=>a_to_g<="1000010";
when"1110"=>a_to_g<="0110000";
when"1111"=>a_to_g<="0111000";
whenothers=>a_to_g<="0000001";
endcase;
endprocess;
endBehavioral;约束文件规定如下:
#Nexys3约束文件:
NET“mclk”LOC=“V10”;
NET“clr”LOC=“T10”;
NET“btn[1]”LOC=“V9”;
NET“btn[0]”LOC=“M8”;
NET“sw[3]”LOC=“T5”;
NET“sw[2]”LOC=“V8”;
NET“sw[1]”LOC=“U8”;
NET“sw[0]”LOC=“N8”;
NET“ld[3]”LOC=“T11”;
NET“ld[2]”LOC=“R11”;
NET“ld[1]”LOC=“N11”;
NET“ld[0]”LOC=“M11”;
NET"a_to_g[0]"LOC="L14";//G#Basys2约束文件:
NET"mclk"LOC="B8";//时钟引脚
NET"clr"LOC="P11"; //SW0
NET"btn[1]"LOC="K3";//SW2
NET"btn[0]"LOC="B4";//SW3
NET"sw[3]"LOC="N3";//SW7
NET"sw[2]"LOC="E2";//SW6
NET"sw[1]"LOC="F3";//SW5
NET"sw[0]"LOC="G3";//SW4
NET"ld[3]"LOC="G1";//LD7
NET"ld[2]"LOC="P1"; //LD6
NET"ld[1]"LOC="N4";//LD5
NET"ld[0]"LOC="N5";//LD4
NET"a_to_g[0]"LOC="M12"; //G
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025年中国万向摇臂钻床市场调查研究报告
- 2025至2031年中国花岗石平板偏摆仪行业投资前景及策略咨询研究报告
- 2025至2031年中国聚丙烯真空抽滤桶行业投资前景及策略咨询研究报告
- 2025至2030年中国美工刀数据监测研究报告
- 2025至2030年中国挂壁式考勤机数据监测研究报告
- 二零二五年度老旧小区消防安全隐患整改合同5篇
- 二零二五年度木地板批发市场租赁合同3篇
- 二零二五年度房屋收购合同物业管理与维护责任范本3篇
- 二零二五年度个人教育培训贷款还款协议8篇
- 建设工程招标代理合同
- 二零二五年度无人驾驶车辆测试合同免责协议书
- 2025年湖北华中科技大学招聘实验技术人员52名历年高频重点提升(共500题)附带答案详解
- 黑龙江省哈尔滨市2024届中考数学试卷(含答案)
- 高三日语一轮复习助词「と」的用法课件
- 毛渣采购合同范例
- 无子女离婚协议书范文百度网盘
- 2023中华护理学会团体标准-注射相关感染预防与控制
- 一年级数学个位数加减法口算练习题大全(连加法-连减法-连加减法直接打印版)
- 五年级上册小数递等式计算200道及答案
- 2024年广东高考政治真题考点分布汇 总- 高考政治一轮复习
- 冀教版五年级下册数学全册教学课件
评论
0/150
提交评论