2020年3月1日 星期日

EX6-3.6 Full Subtractor circuit

EX6-3.6  Full Subtractor circuit


//===============================
// ex6-3.6 Full Substrator circuit

module EX10_14( A, B ,Bin ,Bout ,Diff);

input  A,B,Bin ; // 1位元輸入

output  reg Bout ,Diff ; // Output    1位元輸出

always@ ( A,B) begin

{Bout ,Diff}= A-B-Bin;
end
endmodule


//===============================
// 時間單位 100ns, 時間精確度100 ps
`timescale 100ns/100ps   
module Test_bench;
    // Inputs
    reg A,B,Bin;

    // Outputs
    wire Bout ,Diff ;

    // Instantiate the Unit Under Test (UUT)
    // ex6-3.5 Half Substrator circuit
     EX10_14  UUT (
        .A(A),
        .B(B),
        .Bin(Bin),
        .Bout(Bout) ,
        .Diff(Diff)
    );

    initial begin
        $monitor( A, B ,Bin,Bout ,Diff);
        //Apply inputs
A=1'b0; B=1'b0; Bin=1'b0;
        #100;
{A,B,Bin}=3'b001;
        #100;
{A,B,Bin}=3'b010;
        #100;
{A,B,Bin}=3'b011;
        #100;
{A,B,Bin}=3'b100;
        #100;
        {A,B,Bin}=3'b101;
        #100;
{A,B,Bin}=3'b110;
        #100;
{A,B,Bin}=3'b111;
        #100;             
 
    end
    initial begin
#800  $stop;
end
endmodule



EX6-3.5 Half Subtractor circuit


EX6-3.5   Half  Subtractor circuit

//===============================
// ex6-3.5 Half Substrator circuit

module EX10_13( A, B ,Bout ,Diff);

input  A,B ; // 1位元輸入

output  reg Bout ,Diff ; // Output    1位元輸出

always@ ( A,B) begin

{Bout ,Diff}= A-B;
end
endmodule

//===============================
// 時間單位 100ns, 時間精確度100 ps
`timescale 100ns/100ps     
module Test_bench;
    // Inputs
    reg A,B;

    // Outputs
    wire Bout ,Diff ;

    // Instantiate the Unit Under Test (UUT)
    // ex6-3.5 Half Substrator circuit 
     EX10_13  UUT (
        .A(A), 
        .B(B), 
        .Bout(Bout) ,
        .Diff(Diff)
    );

    initial begin
        $monitor( A, B ,Bout ,Diff);
        //Apply inputs
A=1'b0; B=1'b0; 
        #100;
{A,B}=2'b01;
        #100;
{A,B}=2'b10;
        #100;
{A,B}=2'b11;
        #100;
   
    end
    initial begin
#400  $stop;
end
endmodule

EX6-3.3 4 bit Ripple Full Adder circuit

EX6-3.3    4 bit Ripple  Full Adder circuit

//===============================
// ex6-3-3 4 bits Full Adder circuit

module EX10_12( A,B,Cin ,Cout ,Sum);

input  [3:0] A,B; // 4位元輸入
input  Cin;       // 1位元輸入

output  Cout  ; // Output    1位元輸出
output  [3:0]Sum   ; // Output    4位元輸出

wire   w0,w1,w2 ;

FA u1 ( A[0],B[0],Cin,w0,Sum[0] );
FA u2 ( A[1],B[1],w0,w1,Sum[1] );
FA u3 ( A[2],B[2],w1,w2,Sum[2] );
FA u4 ( A[3],B[3],w2,Cout,Sum[3]);

endmodule


//===============================
// ex6-3 Half Adder circuit
module FA( A,B,Cin ,Cout ,Sum);

input  A,B,Cin; // 1位元輸入

output  reg Cout , Sum  ; // Output    1位元輸出

always@ ( A,B) begin

{Cout,Sum}= A+B+Cin;
end


endmodule
//===============================



// 時間單位 100ns, 時間精確度100 ps
`timescale 100ns/100ps     
module Test_bench;
    // Inputs
    reg [3:0]A,B;
    reg Cin;

    // Outputs
    wire  Cout ;
    wire  [3:0]Sum ;

    // Instantiate the Unit Under Test (UUT)
    // ex6-3-3 4 bits Full Adder circuit 
     EX10_12  UUT (
        .A(A), 
        .B(B), 
        .Cin(Cin),
        .Cout(Cout), 
        .Sum(Sum)
    );

    initial begin
        $monitor( A,B,Cin,Cout ,Sum);
        //Apply inputs
A=4'b0; B=4'b0;Cin=1'b1;  
        #100;
A=4'b1111; B=4'b1111;Cin=1'b1; 
        #100;
A=4'b1010; B=4'b1010;Cin=1'b1; 
        #100;
A=4'b0101; B=4'b0101;Cin=1'b1;
        #100;
A=4'b0101; B=4'b1010;Cin=1'b0;
        #100;
   
    end
    initial begin
#600  $stop;
end
endmodule

EX6-3.2 Full Adder circuit

EX6-3.2  Full Adder circuit

//================================
// ex6-3 Half Adder circuit

module EX10_11( A,B,Cin ,Cout ,Sum);

input  A,B,Cin; // 1位元輸入

output  reg Cout , Sum  ; // Output    1位元輸出

always@ ( A,B) begin

{Cout,Sum}= A+B+Cin;
end
endmodule

//================================
// 時間單位 100ns, 時間精確度100 ps
`timescale 100ns/100ps     
module Test_bench;
    // Inputs
    reg A,B,Cin;

    // Outputs
    wire Cout , Sum ;

    // Instantiate the Unit Under Test (UUT)
    // ex6-3 Half Adder circuit 
     EX10_11  UUT (
        .A(A), 
        .B(B), 
        .Cin(Cin),
        .Cout(Cout), 
        .Sum(Sum)
    );

    initial begin
        $monitor( A,B,Cin,Cout ,Sum);
        //Apply inputs
A=1'b0; B=1'b0;Cin=1'b0;  
        #100;
{A,B,Cin}=3'b001;
        #100;
{A,B,Cin}=3'b010;
        #100;
{A,B,Cin}=3'b011;
        #100;
{A,B,Cin}=3'b100;
        #100;
        {A,B,Cin}=3'b101;
        #100;
  {A,B,Cin}=3'b110;
        #100;
{A,B,Cin}=3'b111;
        #100;
   
    end
    initial begin
#800  $stop;
end
endmodule




EX6-3.1 Half Adder circuit

EX6-3.1 Half Adder circuit

// ex6-3 Half Adder circuit 

module EX10_10( A,B,Cout ,Sum);

input  A,B; // 1位元輸入

output  reg Cout , Sum  ; // Output    1位元輸出

always@ ( A,B) begin

{Cout,Sum}= A+B;
end
endmodule


// 時間單位 100ns, 時間精確度100 ps
`timescale 100ns/100ps     
module Test_bench;
    // Inputs
    reg A,B;

    // Outputs
    wire Cout , Sum ;

    // Instantiate the Unit Under Test (UUT)
    // ex6-3 Half Adder circuit 
     EX10_10  UUT (
        .A(A), 
        .B(B), 
        .Cout(Cout), 
        .Sum(Sum)
    );

    initial begin
        $monitor( A,B,Cout ,Sum);
        //Apply inputs
A=1'b0; B=1'b0;  
        #100;
{A,B}=2'b01;
        #100;
{A,B}=2'b10;
        #100;
{A,B}=2'b11;
        #100;
   
    end
    initial begin
#500  $stop;
end
endmodule

EX6-1 BCD code to 2-4-2-1 code circuit

EX6-1 BCD code to 2-4-2-1 code circuit

//=============================
// Ch6.1 BCD code to 2-4-2-1 code circuit 

module EX10_9( a ,b, c, d, w, x , y ,z);

input  a ,b, c ,d; // 1位元輸入

output  reg  w, x , y ,z  ; // Output    1位元輸出

always@ ( a ,b, c, d) begin
case ({a,b,c,d}) 
4'b0000: {w,x,y,z}=4'b0000;
4'b0001: {w,x,y,z}=4'b0001;
4'b0010: {w,x,y,z}=4'b0010;
4'b0011: {w,x,y,z}=4'b0011;
4'b0100: {w,x,y,z}=4'b0100;
4'b0101: {w,x,y,z}=4'b1011;
4'b0110: {w,x,y,z}=4'b1100;
4'b0111: {w,x,y,z}=4'b1101;
4'b1000: {w,x,y,z}=4'b1110;
4'b1001: {w,x,y,z}=4'b1111;
4'b1010: {w,x,y,z}=4'bzzzz;
4'b1011: {w,x,y,z}=4'bzzzz;
4'b1100: {w,x,y,z}=4'bzzzz;
4'b1101: {w,x,y,z}=4'bzzzz;
4'b1110: {w,x,y,z}=4'bzzzz;
4'b1111: {w,x,y,z}=4'bzzzz;
endcase

end

endmodule

//=============================
// 時間單位 100ns, 時間精確度100 ps
`timescale 100ns/100ps     
module Test_bench;
    // Inputs
    reg a ,b, c ,d;

    // Outputs
    wire w, x , y ,z  ;

    // Instantiate the Unit Under Test (UUT)
    //  Ch6.1 BCD code to 2-4-2-1 code circuit 
     EX10_9  UUT (
        .a(a), 
        .b(b), 
        .c(c), 
        .d(d),
        .w(w), 
        .x(x), 
        .y(y), 
        .z(z)
    );

    initial begin
        $monitor( a ,b, c, d, w, x , y ,z);

        //Apply inputs
a=1'b0; b=1'b0; c=1'b0; d=1'b0;
        #100;
{a,b,c,d}=4'b0001;
        #100;
{a,b,c,d}=4'b0010;
        #100;
{a,b,c,d}=4'b0011;
        #100;
{a,b,c,d}=4'b0100;
        #100;
{a,b,c,d}=4'b0101;
        #100;
{a,b,c,d}=4'b0110;
        #100;
{a,b,c,d}=4'b0111;
        #100;
{a,b,c,d}=4'b1000;
        #100;
{a,b,c,d}=4'b1001;
        #100;
{a,b,c,d}=4'b1010;
        #100;
{a,b,c,d}=4'b1011;
        #100;
{a,b,c,d}=4'b1100;
        #100;
{a,b,c,d}=4'b1101;
        #100;
{a,b,c,d}=4'b1110;
        #100;
{a,b,c,d}=4'b1111;
        #100;
   
    end
    initial begin
#1600  $stop;
end

endmodule


EX5-13 BCD to 7segment display circuit

EX5-13  BCD to 7segment display circuit 


// Ch5.13  BCD to 7segment display circuit

module EX5_13( w,x,y,z,a,b,c,d,e,f,g);

input  w,x,y,z; // 1位元輸入

output  reg a,b,c,d,e,f,g ; // Output    1位元輸出

always@ (w,x,y,z) begin
case ({w,x,y,z})
4'b0000: {a,b,c,d,e,f,g}=7'b111_0111;
4'b0001: {a,b,c,d,e,f,g}=7'b010_0100;
4'b0010: {a,b,c,d,e,f,g}=7'b101_1101;
4'b0011: {a,b,c,d,e,f,g}=7'b101_1011;
4'b0100: {a,b,c,d,e,f,g}=7'b011_1010;
4'b0101: {a,b,c,d,e,f,g}=7'b110_1011;
4'b0110: {a,b,c,d,e,f,g}=7'b110_1111;
4'b0111: {a,b,c,d,e,f,g}=7'b101_0010;
4'b1000: {a,b,c,d,e,f,g}=7'b111_1111;
4'b1001: {a,b,c,d,e,f,g}=7'b111_1010;
4'b1010: {a,b,c,d,e,f,g}=7'bzzz_zzzz;
4'b1011: {a,b,c,d,e,f,g}=7'bzzz_zzzz;
4'b1100: {a,b,c,d,e,f,g}=7'bzzz_zzzz;
4'b1101: {a,b,c,d,e,f,g}=7'bzzz_zzzz;
4'b1110: {a,b,c,d,e,f,g}=7'bzzz_zzzz;
4'b1111: {a,b,c,d,e,f,g}=7'bzzz_zzzz;
endcase

end
endmodule


// 時間單位 100ns, 時間精確度100 ps
`timescale 100ns/100ps     
module Test_bench;
    // Inputs
    reg w,x,y,z;

    // Outputs
    wire a,b,c,d,e,f,g ;

    // Instantiate the Unit Under Test (UUT)
    // ex5.10  F(a,b,c,d) circuit 
     EX5_13  UUT (
.w(w),
.x(x),
.y(y),
.z(z),
        .a(a), 
        .b(b), 
        .c(c), 
        .d(d),
        .e(e),
        .f(f),
        .g(g)
    );

    initial begin
        $monitor( w,x,y,z,a,b,c,d,e,f,g);

        //Apply inputs
w=1'b0; x=1'b0; y=1'b0; z=1'b0;
        #100;
{w,x,y,z}=4'b0001;
        #100;
{w,x,y,z}=4'b0010;
        #100;
{w,x,y,z}=4'b0011;
        #100;
{w,x,y,z}=4'b0100;
        #100;
{w,x,y,z}=4'b0101;
        #100;
{w,x,y,z}=4'b0110;
        #100;
{w,x,y,z}=4'b0111;
        #100;
{w,x,y,z}=4'b1000;
        #100;
{w,x,y,z}=4'b1001;
        #100;
{w,x,y,z}=4'b1010;
        #100;
{w,x,y,z}=4'b1011;
        #100;
{w,x,y,z}=4'b1100;
        #100;
{w,x,y,z}=4'b1101;
        #100;
{w,x,y,z}=4'b1110;
        #100;
{w,x,y,z}=4'b1111;
        #100;
   
    end
    initial begin
#1600  $stop;
end
endmodule


  清除項目編譯快取 執行 flutter clean 重新取得套件依賴 執行 flutter pub get 完整重新編譯並執行 flutter run 1. 新增專案套件 (pubspec.yaml) 在 Flutter 專案根目錄下的 pubspec.yaml 中,新增 ...