对象 <name> 未声明
object <name> is not declared
这是我的代码,据我所知,LEDs
的定义是:
module sevenseg (LEDs,in);
output reg [6:0] LEDs;
input [3:0] in;
always@(in) begin
case(in)
0 : LEDs = 7'b1000000;
1 : LEDs = 7'b1111001;
2 : LEDs = 7'b0100100;
3 : LEDs = 7'b0110000;
4 : LEDs = 7'b0011001;
5 : LEDs = 7'b0001010;
6 : LEDs = 7'b0000010;
7 : LEDs = 7'b1111000;
8 : LEDs = 7'b0000000;
9 : LEDs = 7'b00010000;
default : LEDs = 7'b1111111;
endcase
end
endmodule
编译错误如下:
Error (10161): Verilog HDL error at sevenseg2.v(39): object "LEDs" is
not declared
Error: Quartus II 64-Bit Analysis & Synthesis was unsuccessful. 1
error, 1 warning
Error (293001): Quartus II Full Compilation was unsuccessful. 3
errors, 1 warning
您正在混合使用 ANSI 和 non-ANSI header 样式。这是非法语法。有些 simulator/synthesizer 允许这样做,但这是不好的做法。
您应该使用 ANSI:IEEE Std 1800-2012 § 23.2.2.2 ANSI 样式的端口声明列表
module sevenseg (
output reg [6:0] LEDs,
input [3:0] in );
或non-ANSI:IEEE Std 1800-2012 § 23.2.2.1 Non-ANSI 样式端口声明
module sevenseg (LEDs,in);
output [6:0] LEDs; // only an output here
input [3:0] in;
reg [6:0] LEDs; // declare as reg after all inputs/outputs/inouts
Non-ANSI 是 IEEE 标准 1364-1995 所必需的。自 IEEE 标准 1364-2001 以来就存在对 ANSI 的支持。
接受的答案不正确 - 这在 Verilog (2001/2005) 或 SystemVerilog 中都不是非法的。如果您的编译器认为它是,那么它要么是有问题的,要么是假设 Verilog-1995(没有任何理智的商业编译器会这样做)。
对于 Verilog (1364-2005),12.3.3 规定:
Each port_identifier in a port_expression in the list of ports for the
module declaration shall also be declared in the body of the module as
one of the following port declarations: input, output, or inout
(bidirectional). This is in addition to any other data type
declaration for a particular port— for example, a reg or wire. The
syntax for port declarations is given in Syntax 12-4.
12-4 将 output_declaration
定义为
output_declaration ::=
output [ net_type ] [ signed ] [ range ] list_of_port_identifiers
| output reg [ signed ] [ range ] list_of_variable_port_identifiers
| output output_variable_type list_of_variable_port_identifiers
所以当您有一个简单的端口标识符列表时,output reg
是有效的。 12-4 下方的文字说明
If a port declaration does not include a net or variable type, then the port can be again declared in a net or
variable declaration.
因此 Greg 建议的更改是 允许的 ,而不是必需的(reg
当然是 'variable type')。换句话说,如果您没有 output reg x
,那么您可以将其拆分为两个语句 - output x
和 reg x
.
SystemVerilog (1800-2012) 本质上是相同的——注意 reg
是一个 integer_vector_type
,它是一个 data_type
.
另请注意,ANSI 一词未在 1364 中使用,SystemVerilog 使用不正确。 Task/function/port 声明 而不是 看起来像 ANSI-C,因为您不能在 C 或 C++ 中指定对象列表。例如,您不能声明或定义像 myfunc(int a, b)
这样的函数;它必须是 (int a, int b)
.
我认为问题在于您正试图从 always 块中推送非 ANSI 样式的输出。
你可以
1.转向ANSI风格(反正更方便)或
2. 添加一条电线,将案例结果推送给它,然后 'assign' 电线输出,
3.删除'always'块并写入:
assign LEDs = (in == 0) ? 7'b1000000 : (in == 1) ?
.....
这是我的代码,据我所知,LEDs
的定义是:
module sevenseg (LEDs,in);
output reg [6:0] LEDs;
input [3:0] in;
always@(in) begin
case(in)
0 : LEDs = 7'b1000000;
1 : LEDs = 7'b1111001;
2 : LEDs = 7'b0100100;
3 : LEDs = 7'b0110000;
4 : LEDs = 7'b0011001;
5 : LEDs = 7'b0001010;
6 : LEDs = 7'b0000010;
7 : LEDs = 7'b1111000;
8 : LEDs = 7'b0000000;
9 : LEDs = 7'b00010000;
default : LEDs = 7'b1111111;
endcase
end
endmodule
编译错误如下:
Error (10161): Verilog HDL error at sevenseg2.v(39): object "LEDs" is not declared
Error: Quartus II 64-Bit Analysis & Synthesis was unsuccessful. 1 error, 1 warning
Error (293001): Quartus II Full Compilation was unsuccessful. 3 errors, 1 warning
您正在混合使用 ANSI 和 non-ANSI header 样式。这是非法语法。有些 simulator/synthesizer 允许这样做,但这是不好的做法。
您应该使用 ANSI:IEEE Std 1800-2012 § 23.2.2.2 ANSI 样式的端口声明列表
module sevenseg (
output reg [6:0] LEDs,
input [3:0] in );
或non-ANSI:IEEE Std 1800-2012 § 23.2.2.1 Non-ANSI 样式端口声明
module sevenseg (LEDs,in);
output [6:0] LEDs; // only an output here
input [3:0] in;
reg [6:0] LEDs; // declare as reg after all inputs/outputs/inouts
Non-ANSI 是 IEEE 标准 1364-1995 所必需的。自 IEEE 标准 1364-2001 以来就存在对 ANSI 的支持。
接受的答案不正确 - 这在 Verilog (2001/2005) 或 SystemVerilog 中都不是非法的。如果您的编译器认为它是,那么它要么是有问题的,要么是假设 Verilog-1995(没有任何理智的商业编译器会这样做)。
对于 Verilog (1364-2005),12.3.3 规定:
Each port_identifier in a port_expression in the list of ports for the module declaration shall also be declared in the body of the module as one of the following port declarations: input, output, or inout (bidirectional). This is in addition to any other data type declaration for a particular port— for example, a reg or wire. The syntax for port declarations is given in Syntax 12-4.
12-4 将 output_declaration
定义为
output_declaration ::=
output [ net_type ] [ signed ] [ range ] list_of_port_identifiers
| output reg [ signed ] [ range ] list_of_variable_port_identifiers
| output output_variable_type list_of_variable_port_identifiers
所以当您有一个简单的端口标识符列表时,output reg
是有效的。 12-4 下方的文字说明
If a port declaration does not include a net or variable type, then the port can be again declared in a net or variable declaration.
因此 Greg 建议的更改是 允许的 ,而不是必需的(reg
当然是 'variable type')。换句话说,如果您没有 output reg x
,那么您可以将其拆分为两个语句 - output x
和 reg x
.
SystemVerilog (1800-2012) 本质上是相同的——注意 reg
是一个 integer_vector_type
,它是一个 data_type
.
另请注意,ANSI 一词未在 1364 中使用,SystemVerilog 使用不正确。 Task/function/port 声明 而不是 看起来像 ANSI-C,因为您不能在 C 或 C++ 中指定对象列表。例如,您不能声明或定义像 myfunc(int a, b)
这样的函数;它必须是 (int a, int b)
.
我认为问题在于您正试图从 always 块中推送非 ANSI 样式的输出。
你可以
1.转向ANSI风格(反正更方便)或
2. 添加一条电线,将案例结果推送给它,然后 'assign' 电线输出,
3.删除'always'块并写入:
assign LEDs = (in == 0) ? 7'b1000000 : (in == 1) ?
.....