2020计本一班数字逻辑基础期末
一.教材书P40 图2.45,如图:
1.代码:
module adder(a,b,s1,s0);
input a,b;
output s1,s0;
assign s1=a&b;
assign s0=a^b;
endmodule
2.实验最终(因为没有测试代码,所以我们联合仿真的时候没有波形图,最终如下)
视频链接:https://www.bilibili.com/video/BV1Mh411Y7o6?share_source=copy_web
二.Verilog HDL 高级数字设计(第二版)
P80 例4.8,如图:
1.代码:
module Add_full_unit_delay(output c_out,sum,input a,b,c_in);
wire w1,w2,w3;
Add_half_unit_delay M1(w2,w1,a,b);
Add_half_unit_delay M2(w3,sum,w1,c_in);
or #1 M3(c_out,w2,w3);
endmodule
module Add_half_unit_delay (output c_out,sum,input a,b);
xor #1 M1(sum,a,b);
and #1 M2(c_out,a,b);
endmodule
2.实验最终(因为没有具体的输入,所以是随机用的输入值)如图:
实验链接:https://www.bilibili.com/video/BV14f4y1t7Er?share_source=copy_web
三.Verilog HDL(第二版)数字系统设计及仿真
十二章选题5如图:
1.设计代码:
module digital(TimerH,TimerL,over,Reset,Stop,clk);
output [6:0]TimerH;
output [6:0]TimerL;
output over;
input Reset;
input Stop;
input clk;
wire [1:0]H;
wire [3:0]L;
wire clk_1;
fenpin UO (.clk(clk),.clk_old(clk_1));
basketballtimer U1(over, H[1:0],L[3:0], Reset, Stop,clk_1);
CD4511 U2 (TimerH[6:0], {2'b00,H[1:0]});
CD4511 U3 (TimerL[6:0], L[3:0]);
endmodule
module fenpin (clk_old, clk);
output clk_old;
input clk;
reg[24:0] count;
reg clk_old;
always @(posedge clk)
begin
if(count==25'b1_1001_0000_0000_0000_0000_0000)
begin
clk_old<=~clk_old;
count<=0;
end
else
count<=count+1;
end
endmodule
module basketballtimer (Over,TimerH, TimerL,Reset,Stop,clk_1);
output Over;
output [1:0]TimerH;
output [3:0]TimerL;
input Reset;
input Stop;
input clk_1;
reg [4:0] Q;
assign Over =(Q== 5 'd0);
assign TimerH=Q/10;
assign TimerL=Q%10;
always @(posedge clk_1 or negedge Reset or negedge Stop)
begin
if(~Reset)
Q <= 5'd23;
else
begin
if(~Stop)
Q <= Q;
else
begin
if(Q>5'd0)
Q <= Q - 1'b1;
else
Q <=Q;
end
end
end
endmodule
module CD4511 (Y,A);
output reg [6:0]Y;
input [3:0]A;
always @(*)
begin
case(A)
4'd0: Y<=7'b1000_000;
4 'd1: Y<=7'b1111_001;
4 'd2: Y<=7'b0100_100;
4'd3: Y<=7'b0110_000;
4 'd4:Y<=7'b0011_001;
4 'd5: Y<=7'b0010_010;
4 'd6: Y<=7'b0000_010;
4 'd7: Y<=7'b1111_000;
4 'd8: Y<=7 'b0000_000;
4'd9: Y<=7'b0010_000;
default: Y<=7'b1000_000;
endcase
end
endmodule
2.测试代码:
module tbdigital;
wire [6:0]TimerH;
wire [6:0]TimerL;
wire over;
reg Reset;
reg Stop;
reg clk;
initial
begin
clk=0;
Reset=1;
Stop=1;
#10 Reset=0;
#20 Reset=1;
#200 Stop=0;
#50 Stop=1;
@ (posedge over);
#10 $stop;
end
always #5 clk=~clk;
digital idigital (TimerH, TimerL, over,Reset, Stop, clk);
endmodule
运行仿真可得所示的功能仿具波形图,图甲在复位信号失效后计数器随即开始从23计数至3,此时 stop 信号变为低电平,计数器处于暂停状态。当stop回复到高电平时计数器的时间继续减少,直到减少为0,此时电路输出 over高电平,表示计时结束,功能验证正常。
实验链接:https://www.bilibili.com/video/BV1ZV411s7rj?share_source=copy_web