2017-08-08 77 views
-2

在這個代碼片段中:的Verilog語法錯誤附近的「<=」 case語句

reg [4:0] status_led = 5'b00100; 
    case (status_led) 
     default: begin     
      if (rotation) begin 
       status_led[4] <= status_led[3]; 
       status_led[3] <= status_led[2]; 
       status_led[2] <= status_led[1]; 
       status_led[1] <= status_led[0]; 
       status_led[0] <= status_led[4]; 
      end else if (~rotation) begin 
       status_led[4] <= status_led[0]; 
       status_led[3] <= status_led[4]; 
       status_led[2] <= status_led[3]; 
       status_led[1] <= status_led[2]; 
       status_led[0] <= status_led[1]; 
      end 
     end 
    endcase 

我得到的錯誤「近< =語法錯誤」。爲什麼這是一個錯誤?

+1

之前顯示的代碼是什麼?這是「永遠」塊還是函數的一部分? – mkrieger1

+0

爲什麼你懶得使用'case'語句而只有'default'的情況? – mkrieger1

+0

此代碼是獨立的。原本我有其他案件,但我改變了代碼。我已經用優秀的代碼替換了這些代碼,但是我很好奇爲什麼我會在上面提到的錯誤中遇到以下情況,我需要在將來編寫類似的代碼 –

回答

0

你還沒有定義你的情況,因此錯誤。這應該可以解決你的問題。一個好主意不是將組合和連續的塊總是混合在一起。

reg [4:0] status_led = 5'b00100; 

    [email protected](posedge clk) begin 
    case (status_led) 
     default: begin     
      if (rotation) begin 
       status_led[4] <= status_led[3]; 
       status_led[3] <= status_led[2]; 
       status_led[2] <= status_led[1]; 
       status_led[1] <= status_led[0]; 
       status_led[0] <= status_led[4]; 
      end else if (~rotation) begin 
       status_led[4] <= status_led[0]; 
       status_led[3] <= status_led[4]; 
       status_led[2] <= status_led[3]; 
       status_led[1] <= status_led[2]; 
       status_led[0] <= status_led[1]; 
      end 
     end 
    endcase 
    end