?? 狀態機設計的例子.txt
字號:
【例 10.5】狀態機設計的例子
module FSM(clk,clr,out,start,step2,step3);
input clk,clr,start,step2,step3;
output[2:0] out;
reg[2:0] out;
reg[1:0] state,next_state;
parameter
state0=2'b00,state1=2'b01,
state2=2'b11,state3=2'b10;
/*狀態編碼,采用格雷(Gray)編碼方式*/
always @(posedge clk or posedge clr) /*該進程定義起始狀態*/
begin
if (clr)
state <= state0;
else
state <= next_state;
end
always @(state or start or step2 or step3) /*該進程實現狀態的轉換*/
begin
case (state)
state0:
begin
if (start)
next_state <=state1;
else
next_state <=state0;
end
state1:
begin
end
state2:
begin
next_state <= state2;
if (step2)
next_state <=state3;
else
next_state <=state0;
end
state3:
begin
if (step3)
next_state <=state0;
else
next_state <=state3;
end
default:
next_state <=state0; /*default 語句*/
endcase
end
always @(state) /*該進程定義組合邏輯(FSM 的輸出)*/
begin
case(state)
state0: out=3'b001;
state1: out=3'b010;
state2: out=3'b100;
state3: out=3'b111;
default:out=3'b001; /*default 語句,避免鎖存器的產生*/
endcase end
endmodule
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -