数字电子技术课程设计-冒险游戏
中国创新创业大赛-大年初一
西南交通大学
《数字电子技术A》 课程设计报告
设计题目:冒险游戏有限状态机设计
指导教师:XXX
小组成员及分工:
学号
2016111XXX
2016111XXX
2016111XXX
2016111XXX
2016111XXX
姓名
XXX
XXX
XXX
XXX
XXX
分工
理论分析、方案设计
程序设计、仿真验证
程序设计、仿真验证
硬件调试
硬件调试、报告整理
时间安排:
进程
时间进度
方案设计 程序设计 硬件调试 报告整理
5.13-5.20
5.21-5.28 5.29-6.9 6.9-6.16
一、 设计原理
(1) Room FSM状态装换图
Cave of
cacophony
R•W
R•E
Twisty
Tunnel
Victory Vault
(assert WIN)
R•S
R•N
R•V
Secret
Sword Stash
(assert SW)
R•E
R
•
W
Graveyard
(assert D)
Den
Rapid River
Grievous
R
•
V
R•E
Dragon’s
(2)Room FSM的状态表和输出表:
其中S0-S6的房间分配如下:
S0(000):the Cave of
Cacophony; S1(001):the Twisty Tunnel;
S2(010):the Rapid River; S3(011):the
Secret Sword Stash;
S4(100):the Dragon Den;
S5(101):the Victory Vault;
S6(110):the
Grievous Graveyard;
clk
现态
输入
输出次态
reset n s w e v s
s0 0 0 0 0 1 X s1
SW
win d
0 0 0
s1
s1
s2
s2
s2
s3
s4
s4
X
0
0
0
0
0
0
0
0
1
0 1 0 0 X s2
0 0 1 0 X
s0
0 0 1 0 X s3
1 0 0 0 X s1
0 0 0 1 X
s4
0 0 0 1 X s2
X X X X 1 s5
X X X X 0
s6
X X X X X s0
0
0
0
0
0
1
0
0
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
0
0
1
0
(3)Sword
FSM的状态表和输出表:
输入
clk 现态
R
输出次态
SW
X
0
1
X
no
has
Vhas
Vhas
1
0
0
0
X
No
sword
No sword
Has sword
二、 仿真结果
(1)相关原理图
(2)
仿真波形
i. 闯关成功
由上图可以看出,从第一个房间出发,经过东-南-西-东-
东一系列动作输
出成功
ii.
闯关失败
由上图可以看出,经过东-南-东一系列动作输出失败
三、 引脚分配
四、 Verilog HDL代码
(1)Room
FSM的Verilog HDL实现
module room (
input
clk,reset,v,n,s,e,w,
output reg
win,d,sw,s0,s1,s2,s3,s4,s5,s6
);
reg[2:0]current_room,next_room,room;
定义当前房间和下一房间
parameter
cave=3'b000,tu
nnel=3'b001,river=3'b010,stash=3'b011,dragon=3'b10
0,vic
tory=3'b101,defeated=3'b110;
用二进制数定义房间
always@(posedge clk,posedge reset)
begin
if(reset)
begin
current_room<=cave;room<=cave; end 复位回到第一个房间
else
begin current_room<=next_room;
room<=next_room; end走到下一个房间
end
always @(current_room)
begin
next_room<=cave;
case(current_room)
cave:begin
win<=0;d<=0;sw<=0;s0<=1;s1<=0;s2<=0
;s3<=0;s4<=0;s5<=0;s6<=0; 第一个
房间的状态
if(e) begin next_room<=tunnel;end
else begin
next_room<=cave;end
end
tunnel:begin
s1<=1;s0<=0;s2<=0;s3<=0;s4<=0;s5<=0;s6<=0;
第二个房
间的状态
if(w) begin
next_room<=cave;end
else if(s)
begin next_room<=river;end
else
begin next_room<=tunnel;end
end
river:begin
s2<=1;s1<=0;s3<=0;s4<=0;s5<=0;s6<=0;s0<=0;
第三个房间
的状态
if(n) begin
next_room<=tunnel;end
else if(w)
begin next_room<=stash;end
else
if(e) begin next_room<=dragon;end
else begin next_room<=river;end
end
stash:begin
sw<=1;s3<=1;s2<=0;s4<=0;s5<=0;s6<=0;s0<=0;s1<=0;
第四
个房间的状态
if(e) begin
next_room<=river;end
else begin
next_room<=stash;end
end
dragon:begin
s4<=1;s3<=0;s2<=0;s5<=0;s6<=0;s0<=0;s1<=0;
第五个房
间的状态
if(v)
begin next_room<=victory;end
else begin next_room<=defeated;end
end
victory:begin
next_room<=victory;win<=1;s5<=1;s4<=0;end
第六个房
间即胜利的状态
defeated:begin
next_room<=defeated;d<=1;s6<=1;s4<=0;end
第七个房
间即失败的状态
endcase
end
endmodule
(2)Sword
FSM的Verilog HDL实现
module sword(
input
sw,reset,clk,
output reg v
);
reg state;
always@(posedge clk,posedge
reset)
begin
if(reset) begin
state<=0;v<=0;end 复位
else
case(state) 当前状态选择
0:if (sw) begin state<=1;v<=1;end 胜利
else begin state<=0;v=0;end 失败
1:begin state<=1;v<=1;end
endcase
end
endmodule
胜利