一、实验目的
使初学者很快能够熟悉ModelSim的基本,功能,更详细的软件说明和应用举例讲在后续的章节中进行介绍。
二、实验工具
pc机和Quartur ii软件和modlsim软件。
三、实验代码
module ex8_1(clock,reset,x,y1,y2) ;
input clock,reset;
input x;
output y1,y2;
reg y1,y2;
reg [3:0] cstate,nstate;
parameter s0=4'b0001,s1=4'b0010,
s2=4'b0100,s3=4'b1000;
always @ (posedge clock or posedge reset)
begin
if (reset)
cstate<=s0;
else
cstate<=nstate;
end
always @ (cstate or x)
begin
case (cstate)
s0:begin
if (x==0)
nstate=s1;
else
nstate=s3;
end
s1:begin
if (x==0)
nstate=s2;
else
nstate=s0;
end
s2:begin
if (x==0)
nstate=s3;
else
nstate=s1;
end
s3:begin
if (x==0)
nstate=s0;
else
nstate=s2;
end
default : nstate=s0;
endcase
end
always @ (cstate or x)
begin
case (cstate)
s0 : begin
if (x==0)
y1=1;
else
y1=0;
end
s1 : begin
if (x==0)
y1=0;
else
y1=0;
end
s2 : begin
if (x==0)
y1=0;
else
y1=0;
end
s3 : begin
if (x==0)
y1=0;
else
y1=1;
end
default :y1=0;
endcase
end
always @ (cstate or x)
begin
if (cstate==s0 && x==0)
y2=1;
else if (cstate==s3 && x==1)
y2=1;
else
y2=0;
end
endmodule
四、实验截图
五、实验视频
https://v.douyin.com/eqM9kvs/