always [url=home.php?mod=space&uid=72445]@[/url] (posedge clk or negedge rst )
begin
if (!rst)
state<=State_idle;
else
state<=next_state;
end
//第二段状态机
always @ (posedge clk or negedge rst )
begin
if (!rst)
begin
next_state<=0;
isNew<=0;
end
else
begin
case (state)
/********上电复位后的空状态****************************/
State_idle:
begin
if (isStart)
next_state<=State_new;
else
next_state<=State_new;
end
/**************产生一个新的方块******************************/
State_new:
begin
isNew<=1'b1;
next_state<=State_hold;
end
/***********保持状态等待信号*********************************/
State_hold:
begin
isNew<=1'b0;
isCount<=1'b1;
isMove_D<=0;
isMove_R<=0;
isMove_L<=0;
if(Count_Finish)
begin
next_state<=State_down;
isClear<=1'b1;
end
else if (ps2_data_in==8'h74)
next_state<=State_move_R;
else if (ps2_data_in==8'h6B)
next_state<=State_move_L;
else if (ps2_data_in==8'h72)
next_state<=State_down;
end
/**************判断方块能否下降一格*************************/
State_down:
begin
isClear<=1'b0;
if (Move_D_EN)
begin
isMove_D<=1'b1;
next_state<=State_hold;
end
else
next_state<=State_remove_1;
end
/********************************************/
State_move_L:
begin
if (Move_L_EN)
isMove_L<=1'b1;
next_state<=State_hold;
end
/***********更新方块的坐标信息****************************/
State_move_R:
begin
if (Move_R_EN)
isMove_R<=1'b1;
next_state<=State_hold;
end
/***********方块不能下降后更新背景矩阵的信息*********************************/
State_remove_1:
begin
isremove<=1'b1;
next_state<=State_remove_2;
end
/***********判断是否可以清除*********************************/
State_remove_2:
begin
isremove<=1'b0;
Check_Sig<=1'b1;
if(Check_Finish)
next_state<=State_isdie;
end
/***********判断是否死亡*********************************/
State_isdie:
begin
if (BackGround[3]>16'h8001)
next_state<=State_stop;
else
next_state<=State_new;
end
State_stop:
begin
next_state<=State_idle;
end
endcase
end
end
目前不知道为何很多功能无法实现,求大神路过能留个qq,小弟想大神取些经~~谢谢
l
|