FPGA 学习 05

    科技2022-08-18  92

    FPGA 学习 05_06 3 -8 、 4-16 译码器实验

    my_3_8.v 文件 module my_3_8(a,b,c,out); input a ; //输入端口 A input b ; //输入端口 B input c ; //输入端口 C output reg [7:0]out; //输出端口 out always@(a,b,c) begin case({a,b,c}) 3'b000: out = 8'b0000_0001 ; //使用 = 赋值,必须要是reg的类型,否则无法赋值 3'b001: out = 8'b0000_0010 ; 3'b010: out = 8'b0000_0100 ; 3'b011: out = 8'b0000_1000 ; 3'b100: out = 8'b0001_0000 ; 3'b101: out = 8'b0010_0000 ; 3'b110: out = 8'b0100_0000 ; 3'b111: out = 8'b1000_0000 ; default : out=8'b1111_1111 ; endcase end endmodule my_3_8_tb. v 文件 `timescale 1ns/1ns module my_3_8_tb ; //测试时, input --> reg // output --> wire reg a; reg b; reg c; wire [7:0]out; my_3_8 my_3_8_U1( .a(a), .b(b), .c(c), .out(out) ); initial begin #200 ; a=0 ;b=0 ; c=0 ; #200 ; a=0 ;b=0 ; c=1 ; #200 ; a=0 ;b=1 ; c=0 ; #200 ; a=0 ;b=1 ; c=1 ; #200 ; a=1 ;b=0 ; c=0 ; #200 ; a=1 ;b=0 ; c=1 ; #200 ; a=1 ;b=1 ; c=0 ; #200 ; a=1 ;b=1 ; c=1 ; #200 ; $stop ; end endmodule

    my_4_16.v

    module my_4_16( a, b, c, d, out ); input a ; input b ; input c ; input d ; output reg [15:0]out ; always@(a,b,c,d) begin case ({a,b,c,d}) 4'b0000: out =16'b0000_0000_0000_0001 ; 4'b0001: out =16'b0000_0000_0000_0010 ; 4'b0010: out =16'b0000_0000_0000_0100 ; 4'b0011: out =16'b0000_0000_0000_1000 ; 4'b0100: out =16'b0000_0000_0001_0000 ; 4'b0101: out =16'b0000_0000_0010_0000 ; 4'b0110: out =16'b0000_0000_0100_0000 ; 4'b0111: out =16'b0000_0000_1000_0000 ; 4'b1000: out =16'b0000_0001_0000_0000 ; 4'b1001: out =16'b0000_0010_0000_0000 ; 4'b1010: out =16'b0000_0100_0000_0000 ; 4'b1011: out =16'b0000_1000_0000_0000 ; 4'b1100: out =16'b0001_0000_0000_0000 ; 4'b1101: out =16'b0010_0000_0000_0000 ; 4'b1110: out =16'b0100_0000_0000_0000 ; 4'b1111: out =16'b1000_0000_0000_0000 ; default: out =16'h_ffff ; endcase end endmodule

    my_4_16_tb.v 文件

    `timescale 1ns/1ns module my_4_16_tb; reg a ; reg b ; reg c ; reg d ; wire [15:0]out ; my_4_16 my_4_16_u1( .a(a), .b(b), .c(c), .d(d), .out(out) ); initial begin #200; a=0 ;b=0 ; c=0 ; d= 0; #200 ; a=0 ;b=0 ; c=0 ; d= 1; #200 ; a=0 ;b=0 ; c=0 ; d= 0; #200 ; a=0 ;b=0 ; c=1 ; d= 1; #200 ; a=0 ;b=1 ; c=0 ; d= 0; #200 ; a=0 ;b=1 ; c=0 ; d= 1; #200 ; a=0 ;b=1 ; c=0 ; d= 0; #200 ; a=0 ;b=1 ; c=1 ; d= 1; #200 ; a=1 ;b=0 ; c=0 ; d= 0; #200 ; a=1 ;b=0 ; c=0 ; d= 1; #200 ; a=1 ;b=0 ; c=0 ; d= 0; #200 ; a=1 ;b=0 ; c=1 ; d= 1; #200 ; a=1 ;b=1 ; c=0 ; d= 0; #200 ; a=1 ;b=1 ; c=0 ; d= 1; #200 ; a=1 ;b=1 ; c=0 ; d= 0; #200 ; a=1 ;b=1 ; c=1 ; d= 1; #200 ; $stop ; end endmodule
    Processed: 0.017, SQL: 9