微波EDA网,见证研发工程师的成长!
首页 > 研发问答 > 嵌入式设计讨论 > FPGA,CPLD和ASIC > 大家帮我看看这个verilog代码哪里错了?

大家帮我看看这个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。

  1. if(...)
  2. begin
  3. .....
  4. end
  5. else begin
  6. .....
  7. 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

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top