2020年3月1日 星期日

EX5-12有四隻狗, 其中第3隻狗 碰到任何一隻一定吵架 , 3隻狗 碰在一起一定會吵架

EX5-12 有四隻狗,  其中第3隻狗 碰到任何一隻一定吵架 , 3隻狗 碰在一起一定會吵架

// Ch5.10  F(a,b,c,d) circuit

module EX10_7( a ,b, c, d, F);

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

output  reg F  ; // Output    1位元輸出

always@ ( a ,b, c, d) begin
case ({a,b,c,d})
4'b0000: F=1'b0;
4'b0001: F=1'b0;
4'b0010: F=1'b0;
4'b0011: F=1'b1;
4'b0100: F=1'b0;
4'b0101: F=1'b0;
4'b0110: F=1'b1;
4'b0111: F=1'b1;
4'b1000: F=1'b0;
4'b1001: F=1'b0;
4'b1010: F=1'b1;
4'b1011: F=1'b1;
4'b1100: F=1'b0;
4'b1101: F=1'b1;
4'b1110: F=1'b1;
4'b1111: F=1'b1;
endcase

end
endmodule


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

    // Outputs
    wire F ;

    // Instantiate the Unit Under Test (UUT)
    // ex5.10  F(a,b,c,d) circuit
     EX10_7  UUT (
        .a(a),
        .b(b),
        .c(c),
        .d(d),
        .F(F)
    );

    initial begin
        $monitor( a ,b, c, d, F);

        //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-11 已知四變數布林函數 F(a, b, c, d) = Σ(0,3,4,6,7) + don't care Σ(2,14)

EX5-11 已知四變數布林函數 F(a, b, c, d) = Σ(0,3,4,6,7) + don't care Σ(2,14)

// Ch5.11  F(a,b,c,d) circuit

module EX10_6( a ,b, c, d, F);

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

output  reg F  ; // Output    1位元輸出

always@ ( a ,b, c, d) begin
case ({a,b,c,d})
4'b0000: F=1'b1;
4'b0001: F=1'b0;
4'b0010: F=1'bx;
4'b0011: F=1'b1;
4'b0100: F=1'b1;
4'b0101: F=1'b0;
4'b0110: F=1'b1;
4'b0111: F=1'b1;
4'b1000: F=1'b0;
4'b1001: F=1'b0;
4'b1010: F=1'b0;
4'b1011: F=1'b0;
4'b1100: F=1'b0;
4'b1101: F=1'b0;
4'b1110: F=1'bx;
4'b1111: F=1'b0;
endcase

end
endmodule


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

    // Outputs
    wire F ;

    // Instantiate the Unit Under Test (UUT)
    // ex5.10  F(a,b,c,d) circuit 
     EX10_6  UUT (
        .a(a), 
        .b(b), 
        .c(c), 
        .d(d),
        .F(F)
    );

    initial begin
        $monitor( a ,b, c, d, F);

        //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-10 已知四變數布林函數 F(a, b, c, d) = Σ(0,1,2,5,8,10) + don't care Σ(4,6)

EX5-10 已知四變數布林函數 F(a, b, c, d) = Σ(0,1,2,5,8,10) + don't care Σ(4,6)

// Ch5.10  F(a,b,c,d) circuit

module EX5_10( a ,b, c, d, F);

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

output  reg F  ; // Output    1位元輸出

always@ ( a ,b, c, d) begin
case ({a,b,c,d})
4'b0000: F=1'b1;
4'b0001: F=1'b1;
4'b0010: F=1'b1;
4'b0011: F=1'b0;
4'b0100: F=1'bx;
4'b0101: F=1'b1;
4'b0110: F=1'bx;
4'b0111: F=1'b0;
4'b1000: F=1'b1;
4'b1001: F=1'b0;
4'b1010: F=1'b1;
4'b1011: F=1'b0;
4'b1100: F=1'b0;
4'b1101: F=1'b0;
4'b1110: F=1'b0;
4'b1111: F=1'b0;
endcase

end
endmodule

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

    // Outputs
    wire F ;

    // Instantiate the Unit Under Test (UUT)
    // ex5.10  F(a,b,c,d) circuit 
     EX5_10  UUT (
        .a(a), 
        .b(b), 
        .c(c), 
        .d(d),
        .F(F)
    );

    initial begin
        $monitor( a ,b, c, d, F);

        //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-7 已知五變數布林函數 F(a, b, c, d,e) = Σ(1,3,5,7,8,11,12,17,19,21,23,24,27,28)

EX5-7 已知五變數布林函數 F(a, b, c, d,e) = Σ(1,3,5,7,8,11,12,17,19,21,23,24,27,28)

//===========================
// ex5.7  F(a,b,c,d,e) circuit

module EX10_4( a ,b, c, d, e, F);

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

output  reg F  ; // Output    1位元輸出

always@ ( a ,b, c, d, e) begin
case ({a,b,c,d,e})
5'b0_0000: F=1'b0;
5'b0_0001: F=1'b1;
5'b0_0010: F=1'b0;
5'b0_0011: F=1'b1;

5'b0_0100: F=1'b0;
5'b0_0101: F=1'b1;
5'b0_0110: F=1'b0;
5'b0_0111: F=1'b1;

5'b0_1000: F=1'b1;
5'b0_1001: F=1'b0;
5'b0_1010: F=1'b0;
5'b0_1011: F=1'b1;

5'b0_1100: F=1'b1;
5'b0_1101: F=1'b0;
5'b0_1110: F=1'b0;
5'b0_1111: F=1'b0;

5'b1_0000: F=1'b0;
5'b1_0001: F=1'b1;
5'b1_0010: F=1'b0;
5'b1_0011: F=1'b1;

5'b1_0100: F=1'b0;
5'b1_0101: F=1'b1;
5'b1_0110: F=1'b0;
5'b1_0111: F=1'b1;

5'b1_1000: F=1'b1;
5'b1_1001: F=1'b0;
5'b1_1010: F=1'b0;
5'b1_1011: F=1'b1;

5'b1_1100: F=1'b1;
5'b1_1101: F=1'b0;
5'b1_1110: F=1'b0;
5'b1_1111: F=1'b0;

endcase

end
endmodule

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

    // Outputs
    wire F ;

    // Instantiate the Unit Under Test (UUT)
    // Ch5.3  F(a,b,c,d) circuit 
     EX10_4  UUT (
        .a(a), 
        .b(b), 
        .c(c), 
        .d(d),
        .e(e),
        .F(F)
    );

    initial begin
        $monitor( a ,b, c, d,e, F);

        //Apply inputs
a=1'b0; b=1'b0; c=1'b0; d=1'b0; e=1'b0;
        #100;
{a,b,c,d,e}=5'b0_0001;
        #100;
{a,b,c,d,e}=5'b0_0010;
        #100;
{a,b,c,d,e}=5'b0_0011;
        #100;
{a,b,c,d,e}=5'b0_0100;
        #100;
        {a,b,c,d,e}=5'b0_0101;
        #100;
        {a,b,c,d,e}=5'b0_0110;
        #100;
{a,b,c,d,e}=5'b0_0111;
        #100;
{a,b,c,d,e}=5'b0_1000;
        #100;
{a,b,c,d,e}=5'b0_1001;
        #100;
{a,b,c,d,e}=5'b0_1010;
        #100;
{a,b,c,d,e}=5'b0_1011;
        #100;
{a,b,c,d,e}=5'b0_1100;
        #100;
{a,b,c,d,e}=5'b0_1101;
        #100;
{a,b,c,d,e}=5'b0_1110;
        #100;
{a,b,c,d,e}=5'b0_1111;
#100;
a=1'b1; b=1'b0; c=1'b0; d=1'b0; e=1'b0;
        #100;
{a,b,c,d,e}=5'b1_0001;
        #100;
{a,b,c,d,e}=5'b1_0010;
        #100;
{a,b,c,d,e}=5'b1_0011;
        #100;
{a,b,c,d,e}=5'b1_0100;
        #100;
        {a,b,c,d,e}=5'b1_0101;
        #100;
        {a,b,c,d,e}=5'b1_0110;
        #100;
{a,b,c,d,e}=5'b1_0111;
        #100;
{a,b,c,d,e}=5'b1_1000;
        #100;
{a,b,c,d,e}=5'b1_1001;
        #100;
{a,b,c,d,e}=5'b1_1010;
        #100;
{a,b,c,d,e}=5'b1_1011;
        #100;
{a,b,c,d,e}=5'b1_1100;
        #100;
{a,b,c,d,e}=5'b1_1101;
        #100;
{a,b,c,d,e}=5'b1_1110;
        #100;
{a,b,c,d,e}=5'b1_1111;
        #100;
   
    end
    initial begin
#3300  $stop;
end
endmodule
//===========================

EX5-5 已知四變數布林函數 F(a, b, c, d) = Σ(0,1,2,4,5,6,8,10,11)

 EX5-5 已知四變數布林函數 F(a, b, c, d) = Σ(0,1,2,4,5,6,8,10,11),請執行卡諾圖化簡,求出該函數最簡 SOP 形式。


//===========================
// EX 5.5  F(a,b,c,d) circuit 

module EX10_3( a ,b, c, d, F);

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

output  reg F  ; // Output    1位元輸出

always@ ( a ,b, c, d) begin
case ({a,b,c,d}) 
4'b0000: F=1'b1;
4'b0001: F=1'b1;
4'b0010: F=1'b1;
4'b0011: F=1'b0;
4'b0100: F=1'b1;
4'b0101: F=1'b1;
4'b0110: F=1'b1;
4'b0111: F=1'b0;
4'b1000: F=1'b1;
4'b1001: F=1'b0;
4'b1010: F=1'b1;
4'b1011: F=1'b1;
4'b1100: F=1'b0;
4'b1101: F=1'b0;
4'b1110: F=1'b0;
4'b1111: F=1'b0;
endcase
end

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

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

    // Outputs
    wire F ;

    // Instantiate the Unit Under Test (UUT)
    // ex5.5  F(a,b,c,d) circuit 
     EX10_3  UUT (
        .a(a), 
        .b(b), 
        .c(c), 
        .d(d),
        .F(F)
    );

    initial begin
        $monitor( a ,b, c, d, F);

        //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-3 已知四變數布林函數 F(a, b, c, d)


EX5-3 已知四變數布林函數 F(a, b, c, d) = abc′d′ + a′b′c + ab′c′d + cd,請執行卡諾圖化簡,求出該函數最簡 SOP 形式。


//===============================
// Ch5.3  F(a,b,c,d) circuit

module EX10_2( a ,b, c, d, F);

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

output  reg F  ; // Output    1位元輸出

always@ ( a ,b, c, d) begin
case ({a,b,c,d})
4'b0000: F=1'b0;
4'b0001: F=1'b0;
4'b0010: F=1'b1;
4'b0011: F=1'b1;
4'b0100: F=1'b0;
4'b0101: F=1'b0;
4'b0110: F=1'b0;
4'b0111: F=1'b1;
4'b1000: F=1'b0;
4'b1001: F=1'b1;
4'b1010: F=1'b0;
4'b1011: F=1'b1;
4'b1100: F=1'b1;
4'b1101: F=1'b0;
4'b1110: F=1'b0;
4'b1111: F=1'b1;
endcase

end

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

    // Outputs
    wire F ;

    // Instantiate the Unit Under Test (UUT)
    // Ch5.3  F(a,b,c,d) circuit 
     EX10_2  UUT (
        .a(a), 
        .b(b), 
        .c(c), 
        .d(d),
        .F(F)
    );

    initial begin
        $monitor( a ,b, c, d, F);

        //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
//===============================

EX4-8 已知布林函數F(a, b, c)及 G(a, b, c)


EX4-8 已知布林函數 F(a, b, c) = a + b 以及 G(a, b, c) = ac′ + bc′ + ac + bc,試畫出真值表與其邏輯電路圖。請問 F 與 G 兩函數的關係為何?


//===============================
// Ch4.3  F, G circuit 
module EX10_1( a ,b, c, F,G);

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

output  reg F,G ; // Output    1位元輸出

always@ ( a ,b, c) begin
case ({a,b,c}) 
3'b000:begin
F=1'b0;
G=1'b0;
   end
3'b001:begin
F=1'b0;
G=1'b0;
   end
       
3'b010:begin
F=1'b1;
G=1'b1;
   end
3'b011:begin
F=1'b1;
G=1'b1;
   end
3'b100:begin
F=1'b1;
G=1'b1;
   end
3'b101:begin
F=1'b1;
G=1'b1;
   end
       
3'b110:begin
F=1'b1;
G=1'b1;
   end
3'b111:begin
F=1'b1;
G=1'b1;
   end
endcase
end
endmodule

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

    // Outputs
    wire F,G ;

    // Instantiate the Unit Under Test (UUT)
    //Ch4.3  F, G circuit
     EX10_1  UUT (
        .a(a), 
        .b(b), 
        .c(c), 
        .F(F),
        .G(G)
    );

    initial begin
        $monitor( a ,b, c, F,G);

        //Apply inputs
a=1'b0; b=1'b0; c=1'b0;
        #100;
a=1'b0; b=1'b0; c=1'b1;
        #100;
a=1'b0; b=1'b1; c=1'b0;
        #100;
a=1'b0; b=1'b1; c=1'b1;
        #100;
        a=1'b1; b=1'b0; c=1'b0;
        #100;        
  a=1'b1; b=1'b0; c=1'b1;
        #100;       
  a=1'b1; b=1'b1; c=1'b0;
        #100;       
a=1'b1; b=1'b1; c=1'b1;
        #100;        
        
    end
    initial begin
#1000  $stop;
end
endmodule
//===============================


觀察 F 和 G 兩個布林函數的真值表,對所有的輸入組合而言,F 與 G 的輸出值都相同,則稱此兩個函數是「同等的」、「全等的」或「等效的」(equivalent)。既然真值表完全一樣,我們也可以視上述 F 的邏輯電路圖與 G 的邏輯電路圖,是「同等的」、「全等的」或「等效的」。
假設有兩個電路,當輸入組合相同時,其輸出就會一樣,則這兩個電路可稱之為等效電路。從真值表就可證明,F 與 G 的電路會是等效電路。

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