当前位置:首页 > 华中科技大学数字逻辑实验小设计
.
可以看到运算电路逻辑图只是其中一部分,其中74LS283芯片功能为超前进位的全加器,可以将它设计为一个加法器模块。
由以上的分析,知该设计主要要解决的问题:主模块的设计、寄存器模块的设计、加法器模
块的设计、仿真验证。 由此写出程序代码如下:
功能代码: `timescale 1ns / 1ps //主模块
module JDYS(CIN,S1,S0,CP,A,B,C,D,F); input CIN,S1,S0,CP; input [3:0] A; input [3:0] B; input [3:0] C; input [3:0] D;
.
.
output reg [3:0] F; wire [3:0] xnor1; wire [3:0] and1; wire [3:0] xnor2; wire [3:0] r1; wire [3:0] r2; wire [3:0] r3; wire [3:0] r4; wire [3:0] a; wire aout;
parameter W = 1'b1 xor (xnor1[0],r1[0],r4[0]), xor (xnor1[1],r1[1],r4[1]), xor (xnor1[2],r1[2],r4[2]), xor (xnor1[3],r1[3],r4[3]);
xor (xnor2[0],r2[0],CIN), xor (xnor2[1],r2[1],CIN), xor (xnor2[2],r2[2],CIN), xor (xnor2[3],r2[3],CIN);
register X1(W,A[3],A[2],A[1],A[0],W,W,W,W,CP,r1[3],r1[2],r1[1],r1[0]), register X2(W,B[3],B[2],B[1],B[0],W,W,W,W,CP,r2[3],r2[2],r2[1],r2[0]), register X3(W,C[3],C[2],C[1],C[0],W,W,W,W,CP,r3[3],r3[2],r3[1],r3[0]), register X4(W,D[3],D[2],D[1],D[0],W,W,W,W,CP,r4[3],r4[2],r4[1],r4[0]); add X5(CIN,r1,xnor2,a,aout); and (and1[0],r1[0],r3[0]), and (and1[1],r1[1],r3[1]), and (and1[2],r1[2],r3[2]), and (and1[3],r1[3],r3[3]); always (*) begin
.
.
case({S1,S0}) 2'b00 : begin F <= a; end 2'b01 : begin F <= a; end
2'b10 : F <= and1; 2'b11 : F <= xnor1; endcase end endmodule
//加法器模块
module add (cin,x,y,z,fc); input cin; input [3:0] x; input [3:0] y; output reg [3:0] z; output reg fc; reg [3:0] c; always(cin,x,y,z,fc) begin
z[0] = x[0]^y[0]^cin;
c[0] = ((x[0]^y[0])&cin|x[0]&y[0]); z[1] = x[1]^y[1]^c[0];
c[1] = ((x[1]^y[1])&c[0]|x[1]&y[1]); z[2] = x[2]^y[2]^c[1];
.
.
c[2] = ((x[2]^y[2])&c[1]|x[2]&y[2]); z[3] = x[3]^y[3]^c[2];
fc = ((x[3]^y[3])&c[2]|x[3]&y[3]); end endmodule //寄存器模块
module register(FCLR,D,C,B,A,DR,DL,S1,S0,CP,Q4,Q3,Q2,Q1); input FCLR,D,C,B,A,DR,DL,S1,S0,CP; output reg Q4,Q3,Q2,Q1; parameter W = 1,F = 0;
initial { Q4,Q3,Q2,Q1} = 4'b0000; always (posedge CP) if(!FCLR)
{ Q4,Q3,Q2,Q1} = 0; else if ((~S1)&(~S0))
{ Q4,Q3,Q2,Q1} <= { Q4,Q3,Q2,Q1}; else if(S1&S0)
{ Q4,Q3,Q2,Q1} <= {D,C,B,A}; else if((~S1)&S0&DR)
{ Q4,Q3,Q2,Q1} <= {1,Q3,Q2,Q1}; else if((~S1)&S0&(!DR))
{ Q4,Q3,Q2,Q1} <= {0,Q3,Q2,Q1}; else if(S1&(~S0)&DL)
{ Q4,Q3,Q2,Q1} <= { Q3,Q2,Q1,W}; else if(S1&(~S0)&(~DL))
{ Q4,Q3,Q2,Q1} <= { Q3,Q2,Q1,F}; Endmodule 仿真程序
`timescale 1ns / 1ps
.
共分享92篇相关文档