- 分别采用结构描述和行为描述方式设计一个基本的D触发器,在此基础上,采用结构描述的方式,用8个D触发器构成一个8位移位寄存器。进行功能仿真,查看结果,把上述内容整理到实验报告。
- (1)行为描述:
- 单个D触发器
功能代码:
module shiyan31(q,d,clk);
input d,clk;
output q;
reg q;
always @(posedge clk) %在时钟的每个下降沿
begin
q<=d;
end
endmodule
测试代码:
`timescale 1ns/1ns
module test();
reg d,clk;
wire q;
shiyan31 U1(q,d,clk);
always #10 clk=~clk;
initial
begin clk =0; %每隔20s输入一个d
#20 d=1;
#20 d=0;
#20 d=1;
#20 d=0;
#20 d=1;
#20 d=0;
#20 d=1;
#200 $finish;
end
endmodule
- 8位D触发的移位寄存器:
功能程序:
module shiyan31(q,d,clk);
input d,clk;
output q;
wire d;
wire[7:0] q;
D U2(q[0],d,clk); %调用8次Module D,第一个的输入为d,其它输入为上一级的输出
D U3(q[1],q[0],clk);
D U4(q[2],q[1],clk);
D U5(q[3],q[2],clk);
D U6(q[4],q[3],clk);
D U7(q[5],q[4],clk);
D U8(q[6],q[5],clk);
D U9(q[7],q[6],clk);
endmodule
module D(q,d,clk);%一个D触发器的module
input d,clk;