2014年6月3日 星期二

if-else Statements

if-else Statements
General syntax is as follows:
ifcondition )     statement;


Consider the example
ifhold == 0 )     counter = counter + 1;

ifreset ) 

   counter = 0; else 
   counter = counter + 1;


ifreset ) 
begin 
   counter <= 0;
   over_flow <= 0; 
end
else if ( counter == 15 ) begin 
   counter <= 0;
   over_flow <= 1; 
end
else
begin
   
counter <= counter + 1;
   over_flow <= 0; 

end 

  
if-else statements should be used inside initial or always blocks. 

module addsub (a, b, addnsub, result);

        input[7:0]  a;
        input[7:0]  b;
        input       addnsub;
        output[8:0] result;

        reg[8:0]    result;

        always @(a or b or addnsub)
        begin
           if (addnsub)
              result = a + b;
           else
              result = a - b;
        end
endmodule

If addnsub is true( nonzero ), result will be a+b, otherwise result will be a-b.

沒有留言:

張貼留言

ESP32 遠端感應控制系統

ESP32 遠端感應控制系統 目前的架構設計(結合了 ESP32、RFID、MQTT、Node-RED 與 Telegram 遠端雙向控制 ),這個系統的核心價值在於 即時感應、雲端中繼、智慧自動化與即時通訊回報 。 整個架構透過無線網路(Wi-Fi),將現場的硬體感測端、雲端訊...