16、10 e3=0;
#10 e1=0;
#10 e2=0;
#10 e3=1;
end
endmodule
//74HC153代码
module HC153(S,I1,I2,E1,E2,Y1,Y2);
input [1:0]S;
input [3:0]I1;
input [3:0]I2;
input E1,E2;
output Y1,Y2;
reg Y1,Y2;
always@(S,I1,I2,E1,E2)
begin
if(E1)
17、
Y1=0;
else
Y1=I1[S];
if(E2)
Y2=0;
else
Y2=I2[S];
end
endmodule
//74HC153测试平台代码
module test_HC153;
reg [1:0]s;
reg[3:0]i1;
reg[3:0]i2;
reg e1,e2;
wire y1,y2;
HC153 u3(s,i1,i2,e1,e2,y1,y2);
18、 initial
begin
e1=1;
e2=1;
#15 e1=0;e2=0;
end
initial
begin
s=0;i1=0;i2=0;
#10 i1=4'b1001;i2=4'b1100;
#10 s=1;
#10 s=2;
#10 s=3;
end
endmodule
//74HC85代码
module HC85(A,B,I,Q);
input [3:0
19、]A,B;
input [2:0]I;
output [2:0]Q;
reg [2:0]Q;
always@(A,B)
begin
if(A>B)
Q=3'b100;
else if(A
20、3'b101;
else
Q=I;
end
endmodule
//74HC85测试平台代码
module test_HC85;
reg [3:0]a,b;
reg [2:0]i;
wire [2:0]q;
HC85 u4(a,b,i,q);
initial
begin
i=0;
repeat(4)
#10 i=$random;
end
initial
begin
21、 a=3;b=1;
#10
a=1;b=4;
#10
a=0;b=0;
#10
a=6;b=1;
#10
a=5;b=9;
end
endmodule
//74HC283代码
module HC283(CIN,A,B,COUT,S);
input CIN;
input [3:0]A,B;
output COUT;
output [3:0]S;
reg COUT;
reg [
22、3:0]S;
always@(CIN,A,B)
begin
{COUT,S}=CIN+A+B;
end
endmodule
//74HC283测试平台代码
module test_HC283;
reg cin;
reg [3:0]a,b;
wire cout;
wire [3:0]s;
HC283 u5(cin,a,b,cout,s);
initial
begin
cin=0;
repeat(20)
#15
23、 cin=$random;
end
initial
begin
a=0;
repeat(20)
#10 a=$random;
end
initial
begin
b=0;
repeat(20)
#10 b=$random;
end
endmodule
//74HC4511代码
module HC4511(LE,BI,LT,A,Y);
input LE,BI,LT;
inpu
24、t [3:0]A;
output [6:0]Y;
reg [6:0]Y;
always@(LE,BI,LT,A)
begin
if(!LT)
Y=7'b1111111;
else if(!BI)
Y=0;
else if(LE)
Y=Y;
else
case (A)
4'd0:Y=7'b1111110;//数字按abcdefg顺序
4'd1:Y=7'b011
25、0000;
4'd2:Y=7'b1101101;
4'd3:Y=7'b1111001;
4'd4:Y=7'b0110011;
4'd5:Y=7'b1011011;
4'd6:Y=7'b1011111;
4'd7:Y=7'b1110000;
4'd8:Y=7'b1111111;
4'd9:Y=7'b1111011;
4'd10:Y=7'b1110111;
4'd11:Y=7'b0
26、011111;
4'd12:Y=7'b1001110;
4'd13:Y=7'b0111101;
4'd14:Y=7'b1001111;
4'd15:Y=7'b1000111;
default:;
endcase
end
endmodule
//74HC4511测试平台代码
module test_HC4511;
reg le,bi,lt;
reg [3:0]a;
wire [6:0]y;
HC4511 u6(
27、le,bi,lt,a,y);
initial
begin
lt=0;
#10
lt=1;
bi=0;
#10
bi=1;
le=1;
#10
le=0;
end
initial
begin
a=0;
repeat(30)
#20 a=$random;
end
endmodule
3、第一次仿真结果截图(任选一个模块,请注
28、明)
74HC85:
4、综合结果(截图)
5、第二次仿真结果(综合后仿真截图)。回答输出信号是否有延迟,最长延迟时间约为多少?
最大延迟约为700ps。
6、布局布线(引脚分配截图)
7、第三次仿真结果(布局布线后)。回答输出信号是否有延迟,最长延迟时间约为多少?分析是否有出现竞争冒险。
最大延迟约为11500ps,出现竞争冒险。
8、烧录,给老师检查。
3、时序逻辑电路
一、实验目的
1、了解基于Verilog的时序逻辑电路的设计及其验证。
2、熟悉利用EDA工具进行设计及仿真的流程。
3、学习针对实际时序逻辑电路芯片74HC74、74HC112
29、74HC194、74HC161进行VerilogHDL设计的方法。
二、实验环境
Libero仿真软件。
三、实验内容
1、熟练掌握Libero软件的使用方法。
2、进行针对74系列时序逻辑电路的设计,并完成相应的仿真实验。
3、参考教材中相应章节的设计代码、测试平台代码(可自行编程),完成74HC74、74HC112、74HC161、74HC194相应的设计、综合及仿真。
4、提交针对74HC74、74HC112、74HC161、74HC194(任选一个)的综合结果,以及相应的仿真结果。
四、实验结果和数据处理
1、74HC74、74HC112、74HC161、74H
30、C194四个模块及测试平台代码设计。
注:将以上4个模块及相应测试平台代码均写在一个工程文件中。
工程(project)名要求:学号末4位+下划线+seq,例如陈静(3212005896)的工程名为“5896_seq”。
设计模块代码文件名要求:
A) 4个模块可以写在同一个Verilog文件中,如果这样,文件命名要求同上,即“5896_seq.v”;
B) 4个模块分别写在不同的Verilog文件中,如果这样,文件命名要求:学号末4位+下划线+芯片名,例如“5896_74HC161.v”。
测试平台文件名:分别为每个模块建立一个测试平台文件,文件命名要求:test+下划线+芯片名
31、例如“test_74HC161.v”。
(1)代码清单
//74HC74代码
module HC74(S1,S2,R1,R2,CLK1,CLK2,D1,D2,Q1,QF1,Q2,QF2);
input S1,S2,R1,R2,CLK1,CLK2,D1,D2;
output Q1,QF1,Q2,QF2;
reg Q1,QF1,Q2,QF2;
always@(posedge CLK1)
begin
if(!S1&&R1)
begin
Q1<=1;QF1<=0;
32、 end
else if(S1&&!R1)
begin
Q1<=0;QF1<=1;
end
else if(!S1&&!R1)
begin
Q1<=1;QF1<=1;
end
else
begin
Q1<=D1;QF1<=!D1;
end
end
always@(posedge CLK2)
begin
i
33、f(!S2&&R2)
begin
Q2<=1;QF2<=0;
end
else if(S1&&!R1)
begin
Q2<=0;QF2<=1;
end
else if(!S1&&!R1)
begin
Q2<=1;QF2<=1;
end
else
begin
Q2<=D2;QF2<=!D2;
end
34、 end
endmodule
//74HC74测试平台代码
`timescale 1ns/1ns
module test_HC74;
reg s1,s2,r1,r2,clk1,clk2,d1,d2;
wire q1,qf1,q2,qf2;
HC74 u1(s1,s2,r1,r2,clk1,clk2,d1,d2,q1,qf1,q2,qf2);
initial
begin
clk1=0;
#400 $finish;
end
always
#1
35、0 clk1=~clk1;
initial
begin
clk2=0;
end
always
#10 clk2=~clk2;
initial
begin
s1=0;
repeat(20)
#20 s1=$random;
end
initial
begin
s2=0;
repeat(20)
#20 s2=$random;
36、end
initial
begin
r1=1;
repeat(20)
#20 r1=$random;
end
initial
begin
r2=1;
repeat(20)
#20 r2=$random;
end
initial
begin
d1=0;
repeat(20)
#20 d1=$random;
end
37、initial
begin
d2=0;
repeat(20)
#20 d2=$random;
end
endmodule
//74HC112代码
module HC112(S1,S2,,R1,R2,CLK1,CLK2,J1,J2,K1,K2,Q1,QF1,Q2,QF2);
input S1,S2,R1,R2,CLK1,CLK2,J1,J2,K1,K2;
output Q1,QF1,Q2,QF2;
reg Q1,Q2;
assign QF1=~Q1;
assi
38、gn QF2=~Q2;
always@(negedge CLK1,negedge S1,negedge R1)
begin
if(!S1&&R1)
Q1<=1;
else if(S1&&!R1)
Q1<=0;
else if(!S1&&!R1)
Q1<=1;
else
case({J1,K1})
2'b00:Q1<=Q1;
2'b01:Q1<=0;
39、 2'b10:Q1<=1;
2'b11:Q1<=~Q1;
endcase
end
always@(negedge CLK2,negedge S2,negedge R2)
begin
if(!S2&&R2)
Q2<=1;
else if(S2&&!R2)
Q2<=0;
else if(!S2&&!R2)
Q2<=1;
else
case(
40、{J2,K2})
2'b00:Q2<=Q2;
2'b01:Q2<=0;
2'b10:Q2<=1;
2'b11:Q2<=~Q2;
endcase
end
endmodule
//74HC112测试平台代码
`timescale 1ns/1ns
module test_HC112;
reg s1,s2,r1,r2,clk1,clk2,j1,j2,k1,k2;
wire q1,qf1,q2,qf2;
HC112 u1(s1,
41、s2,r1,r2,clk1,clk2,j1,j2,k1,k2,q1,qf1,q2,qf2);
initial
begin
clk1=0;
end
always
#10 clk1=~clk1;
initial
begin
s1=0;
repeat(20)
#20 s1=$random;
end
initial
begin
r1=0;
repeat(20)
#20 r1=$r
42、andom;
end
initial
begin
j1=0;
repeat(20)
#20 j1=$random;
end
initial
begin
k1=0;
repeat(20)
#20 k1=$random;
end
initial
begin
clk2=0;
end
always
#10 clk2=~clk2;
initia
43、l
begin
s2=0;
repeat(20)
s2=$random;
end
initial
begin
r2=0;
repeat(20)
#20 r2=$random;
end
initial
begin
j2=0;
repeat(20)
#20 j2=$random;
end
initial
begin
k2=0;
44、 repeat(20)
#20 k2=$random;
end
initial
#450 $finish;
endmodule
//74HC161代码
module HC161(MR,CP,CEP,CET,PE,D,Q,TC);
input MR,CP,CEP,CET,PE;
input [3:0]D;
output [3:0]Q;
output TC;
reg [3:0]Q;
reg TC;
always@(posedge CP)
begin
45、
if(!MR)
Q<=0;
else if(!PE)
Q<=D;
else if(!CEP||!CET)
Q<=Q;
else
Q<=Q+1;
end
always@(posedge CP)
begin
if(Q==4'b1110)
TC<=1;
else
TC<=0;
end
endm
46、odule
//74HC161测试平台代码
`timescale 1ns/1ns
module test_HC161;
reg mr,cp,cep,cet,pe;
reg [3:0]d;
wire [3:0]q;
wire tc;
HC161 u1(mr,cp,cep,cet,pe,d,q,tc);
initial
begin
mr=0;
#15
mr=1;
pe=0;
d=0;
#15
c
47、ep=1;
cet=1;
pe=1;
#200
cep=0;
#15
cet=0;
end
initial
begin
cp=0;
#300 $finish;
end
always
#5 cp=~cp;
endmodule
//74HC194代码
module HC194(MR,S,CP,DSR,DSL,D,Q);
input MR,DSR
48、DSL,CP;
input [1:0]S;
input [3:0]D;
output [3:0]Q;
reg [3:0]Q;
always@(posedge CP,negedge MR)
begin
if(!MR)
Q<=0;
else
case(S)
0:Q<=Q;
1:Q<={DSR,Q[3:1]};
2:Q<={Q[2:0],DSL};
3:Q<=D;
49、 endcase
end
endmodule
//74HC194测试平台代码
`timescale 1ns/1ns
module test_HC194;
reg mr,cp,dsr,dsl;
reg [1:0]s;
reg [3:0]d;
wire [3:0]q;
HC194 u1(mr,s,cp,dsr,dsl,d,q);
initial
begin
cp=0;
s=3;
repeat(20)
#20 s=$r
50、andom;
end
always
#10 cp=~cp;
initial
begin
dsr=0;
repeat(20)
#20 dsr=$random;
end
initial
begin
dsl=0;
repeat(20)
#20 dsl=$random;
end
initial
begin
d=0;