大家帮我看看这个verilog代码哪里错了?
时间:10-02
整理:3721RD
点击:
module count(clk, rst, ld);
input clk, rst;
output ld;
reg ld;
reg [25:0] cnt;
always @(posedge clk)
begin
if(rst)
cnt <= 26'b0000_0000_0000_0000_0000_0000_00;
ld<=0;
else if(cnt == 26'b1110_0100_1110_0001_1100_0000_00)
cnt <= 26'b0000_0000_0000_0000_0000_0000_00;
ld <= ~ld;
else
cnt <= cnt+1;
end
endmodule
错误:expecting statement
之前用的是VHDL,现在开始学习verilog。
input clk, rst;
output ld;
reg ld;
reg [25:0] cnt;
always @(posedge clk)
begin
if(rst)
cnt <= 26'b0000_0000_0000_0000_0000_0000_00;
ld<=0;
else if(cnt == 26'b1110_0100_1110_0001_1100_0000_00)
cnt <= 26'b0000_0000_0000_0000_0000_0000_00;
ld <= ~ld;
else
cnt <= cnt+1;
end
endmodule
错误:expecting statement
之前用的是VHDL,现在开始学习verilog。
- if(...)
- begin
- .....
- end
- else begin
- .....
- end
if(rst)
begin
cnt <= 26'b0000_0000_0000_0000_0000_0000_00;
ld<=0;
end
else if(cnt == 26'b1110_0100_1110_0001_1100_0000_00)
begin
cnt <= 26'b0000_0000_0000_0000_0000_0000_00;
ld <= ~ld;
end
else
cnt <= cnt+1;
这样写貌似也是错的,楼上那样写的语法才是正确的,同样感谢!
之前我之所以那样写是参考书上的一个if else 用法,搞半天是书错了,郁闷。
3楼没错,就是少两个begin end而已
寻宝人 has got the point
