Verilog HDL 的2位BCD码加法器
reg [6:0]displayA0;
reg [6:0]displayA1; //定义其类型为寄存器类型;
reg [6:0]displayB0;
reg [6:0]displayB1;
always@(A0 or A1 or B0 or B1) //当输入A 、B中任何一位变化,即执行输入显示程序; begin
case(A0) //输入A0显示
4'd0:displayA0=7'b1000000;
4'd1:displayA0=7'b1111001;
4'd2:displayA0=7'b0100100;
4'd3:displayA0=7'b0110000;
4'd4:displayA0=7'b0011001;
4'd5:displayA0=7'b0010010;
4'd6:displayA0=7'b0000010;
4'd7:displayA0=7'b1011000;
4'd8:displayA0=7'b0000000;
4'd9:displayA0=7'b0010000;
default: displayA0=7'b1000000; //默认时,数码管显示数字“0”;
endcase
case(A1) //输入A1显示
4'd0:displayA1=7'b1000000;
4'd1:displayA1=7'b1111001;
4'd2:displayA1=7'b0100100;
4'd3:displayA1=7'b0110000;
4'd4:displayA1=7'b0011001;
4'd5:displayA1=7'b0010010;
4'd6:displayA1=7'b0000010;
4'd7:displayA1=7'b1011000;
4'd8:displayA1=7'b0000000;
4'd9:displayA1=7'b0010000;
default:displayA1=7'b1000000; //默认时,数码管显示数字“0”;
endcase
case(B0) //输入B0显示
4'd0:displayB0=7'b1000000;
4'd1:displayB0=7'b1111001;
4'd2:displayB0=7'b0100100;
4'd3:displayB0=7'b0110000;
4'd4:displayB0=7'b0011001;
4'd5:displayB0=7'b0010010;
4'd6:displayB0=7'b0000010;
4'd7:displayB0=7'b1011000;