斑主帮我看一下这个用法哪里出了错吧,非常感激了>。。>
module pingpong(clock,reset,transa,transb,recepta,receptb,posa,posb,marka,markb,way);
input clock,reset,transa,transb,recepta,receptb;
output posa,posb,marka,markb,way;
reg [3:0] posa,marka,markb;
wire [3:0] posb;
reg [4:0] state,temp1,temp2;
reg [7:0] way;
parameter s0=1,s1=2,s2=4,s3=8,s4=16;
always @(posedge clock)
begin
if(reset) state=s0;
else
begin
case(state)
s0: begin
if(transa) state=s1;
else if(transb) state=s2;
end
s1:begin
if((posa==8)&&(!receptb)) state=s3;
else if((posa==8)&&receptb) state=s2;
else if((posa!=8)&&receptb) state=s3;
end
s2:begin
if((posa==1)&&(!recepta)) state=s4;
else if((posa==1)&&recepta) state=s1;
else if((posa!=1)&&recepta) state=s4;
end
s3:if(transa) state=s1;
s4:if(transb) state=s2;
endcase
end
end
assign posb=posa;
always @(posedge clock)
begin
if(reset)
begin
temp1=0;
temp2=0;
posa=0;
way=0;
marka=0;
markb=0;
end
else
begin
temp2=temp1;
temp1=state;
if(temp1!=temp2)
begin
case(temp1)
s1:begin
if((temp2==s2)&&(temp1==s1)) begin posa=2;way=64; end
else begin posa=1; way=128;end
end
s2:begin
if((temp2==s1)&&(temp1==s2)) begin posa=7;way=2; end
else begin posa=8;way=1;end
end
s3:begin marka=marka+1;way=0;posa=0;end
s4:begin markb=markb+1;way=0;posa=0;end
endcase
end
else if(state==s1) begin posa=posa+1;way=way>>1;end
else if(state==s2) begin posa=posa-1;way=way<<1;end
end
end
endmodule
|