数字设计第三次实验——综合实验(七段数码管)

    xiaoxiao2022-07-14  162

    要求:1~10数字在七段数码管显示。

    思路:

    一、10_4编码器实现数字转4位BCD。 二、4_7译码器实现数码管显示。 三、顶层模块实现子模块实例化。

    收获:

    做的过程中被两个子模块中的输入输出交换难住,百度得:在顶层模块中实例化子模块时,定义wire类型实现子模块间输入输出端口连接。创建项目时项目名必须和顶层模块名一致,否则报错。如果begin-end中包含有局部声明(比如用到的for循环中的i),则他必须被命名(必须有一个标志)。如果要禁止一个begin-end块,那么被禁止的begin-end必须有名字。

    下面是代码和引脚分配

    AC模块一代码:

    module encoder10_4(a1,out1,none_on1); input [9:0]a1; output [3:0]out1; output none_on1; reg [3:0]out1; reg none_on1; always @(a1) begin:local integer i; out1=0; none_on1=1; for(i=0;i<10;i=i+1) begin if(a1[i]) begin out1=i; none_on1=0; end end end endmodule

    AC模块二代码:

    module decode4_7(decodeout1,indec); output[6:0] decodeout1; input[3:0] indec; reg[6:0] decodeout1; always @(indec) begin case(indec) 4'b0000:decodeout1=7'b1111110; 4'b0001:decodeout1=7'b0110000; 4'b0010:decodeout1=7'b1101101; 4'b0011:decodeout1=7'b1111001; 4'b0100:decodeout1=7'b0110011; 4'd0101:decodeout1=7'b1011011; 4'd0110:decodeout1=7'b1011111; 4'b0111:decodeout1=7'b1110000; 4'b1000:decodeout1=7'b1111111; 4'b1001:decodeout1=7'b1111011; 4'b1010:decodeout1=7'b1110111;//A 4'b1011:decodeout1=7'b0011111;//b 4'b1100:decodeout1=7'b1001110;//C 4'b1101:decodeout1=7'b0111101;//d 4'b1110:decodeout1=7'b1001111;//E 4'b1111:decodeout1=7'b1000011;//F default: decodeout1=7'bx; endcase end endmodule

    ACtop模块代码:

    module top(a,decodeout,none_on); input [0:9]a; input none_on; output [6:0]decodeout; wire e; encoder10_4 c(.a1(a),.none_on1(none_on),.out1(e)); decode4_7 d(.decodeout1(decodeout),.indec(e)); endmodule

    引脚分配:略。。。

    最新回复(0)