在verilog中将BCD分段为7解码器

segment BCD to 7 decoder in verilog

我正在编写用于模拟 bcd 到七段解码器的代码。当我这样做时,波形 window(在 Modelsim 中)出现红线和蓝线,这意味着输入未被驱动且输出处于未定义状态。但是当我通过强制值 运行 代码时,它会显示正确的结果。由此我可以确定问题出在我的测试台上。如果有人可以查看 m 代码并指出我做错了什么,我将不胜感激。 代码

//BCD to seven segment display
module seven_segment;
reg [3:0] BCD;
wire [6:0] display;
parameter stop_time = 200;


bcd_seven n(display,BCD);       //Instantiation of the bcd to seven segment      display code

initial #stop_time $finish;

initial
begin
BCD = 0;
#10 BCD = 1;
#10 BCD = 2;
#10 BCD = 3;
#10 BCD = 4;
#10 BCD = 5;
#10 BCD = 6;
#10 BCD = 7;
#10 BCD = 8;
#10 BCD = 9;
end
initial begin
$monitor("display = %d BCD = %b",display,BCD);
end
endmodule 

//Decsription of the BCD to seven segment display
module bcd_seven(D,BCD);
output  D; 
reg [6:0] D;
input [3:0] BCD;

parameter BLANK = 7'b0000000;
parameter ZERO = 7'b1111110;
parameter ONE = 7'b0110000;
parameter TWO = 7'b1101101;
parameter THREE = 7'b1111001;
parameter FOUR = 7'b0110011;
parameter FIVE = 7'b1011011;
parameter SIX = 7'b1011111;
parameter SEVEN = 7'b1110000;
parameter EIGHT = 7'b1111111;
parameter NINE = 7'b1111011;

//I have doubt especially in this section
always @(BCD)
case(BCD)
0: D = ZERO;
1: D = ONE;
2: D = TWO;
3: D = THREE;
4: D = FOUR;
5: D = FIVE;
6: D = SIX;
7: D = SEVEN;
8: D = EIGHT;
default: D = BLANK;
endcase
endmodule

我注意到您的代码中有一个错误。您缺少 BCD = 9 的 case 语句。但这并不能解释您看到的其他问题。