2021-06-28

1.实验目的:
下载Quartur ii软件和modlsim并进行联合仿真。

2.实验内容:
参照哔哩哔哩中教程的代码,然后用quartus ii和modlsim进行联合仿真
3.实验原理:按照视频上的内容,书写和运行代码,完成联合仿真操作。
4实验工具:
pc机和Quartur ii软件和modlsim软件。

5.实验截图:
2021-06-28

6.实验视频:

请下载哔哩哔哩动画打开此网址【仿真-哔哩哔哩】https://b23.tv/vklN5L
7实验代码:
module pingp(clk, reset, push1, push0, led, decode1, decode2, decode3, decode4, clk_out);
input clk, reset;
input push1, push0;
output [6:0] led, decode1, decode2, decode3, decode4;
output clk_out;

ctl ctll(.clk(clk),.reset(reset),.push1(push1),.push0(push0),.led(led),
.decode1(decode1),.decode2(decode2),.decode3(decode3),.decode4(decode4));

endmodule

module ctl(clk, reset, push1, push0, led, decode1, decode2, decode3, decode4);
input clk, reset;
input push1, push0;
output [6:0] led, decode1, decode2, decode3, decode4;
reg [3:0] M,N;
reg [6:0] led, decode1, decode2, decode3, decode4;
reg [2:0] state;
parameter s0=3’b000,
s1=3’b001,
s2=3’b010,
s3=3’b011,
s4=3’b100;
always@(posedge clk)
begin
if(reset)
begin
led<=7’b0000000;
M<=4’b0000;
N<=4’b0000;
end
else
begin
case(state)
s0: //初始发球
begin
led<=7’b0000000;

					if(push0)
						begin
							state<=s1;
							led<=7'b1000000;
						end
					else if(push1)
						begin
							state<=s3;
							led<=7'b0000001;
						end
				end
				s1:								//甲发球或甲接球后,球的移动
				begin
					if(push1)
						begin
							state<=s0;
							M<=M+4'b0001;
						end
					else if(led==7'b0000001)
						begin
							state<=s2;
						end
					else
						begin
							state<=s1;
							led[6:0]<=led[6:0]>>1;
						end
				end
				s2:if(push1)			//乙接球
				
begin
							state<=s3;
							led<=7'b0000010;
						end
					else
						begin
							state<=s0;
							M<=M+4'b0001;
						end
				s3:					//乙发球或接球后,球的移动
				begin
					if(push1)
						begin
							state<=s0;
							N<=N+4'b0001;
						end
					else if(led==7'b1000000)
						begin
							state<=s4;
						end
					else
						begin
							state<=s3;
							led[6:0]<=led[6:0]<<1;
						end
				end
				s4:											//甲接球
					if(push0)
						begin
							state<=s1;
							led=7'b0100000;
						end
					else
						begin
							state<=s0;
							N<=N+4'b0001;
						end
				default:state<=s0;
			endcase
			
			if(M==4'b1011 || N==4'b1011)
				begin
					M<=4'b0000;
					N<=4'b0000;
				end
			case(M)				//显示甲得分
				8'b0000: begin
							decode1<=7'b1000000;
							decode2<=7'b1000000;
						end
				8'b0001: begin
							decode2<=7'b1000000;
							decode1<=7'b1111001;
						end
				8'b0010: begin
							decode2<=7'b1000000;
							decode1<=7'b0100100;
						end
				8'b0011: begin
							decode2<=7'b1000000;
							decode1<=7'b0101111;
						end
				8'b0100: begin
							decode2<=7'b1000000;
							decode1<=7'b0011001;
						end							
				8'b0101: begin
							decode2<=7'b1000000;
							decode1<=7'b0010010;
						end
				8'b0110: begin
							decode2<=7'b1000000;
							decode1<=7'b1000010;
						end
				8'b0111: begin
							decode2<=7'b1000000;
							decode1<=7'b1111000;
						end		
				8'b1000: begin
							decode2<=7'b1000000;
							decode1<=7'b0000000;
						end
				8'b1001: begin
							decode2<=7'b1000000;
							decode1<=7'b0010000;
						end	
				8'b1010: begin
							decode2<=7'b1111001;
							decode1<=7'b1000000;
						end
				8'b1011: begin
							decode2<=7'b1111001;
							decode1<=7'b1111001;
						end
				default: begin
							decode2<=7'b1000000;
							decode1<=7'b1000000;
						end
				endcase
		end
				case(N)										//显示乙得分
					8'b0000: begin
						decode4<=7'b1000000;
						decode3<=7'b1000000;
						end
					8'b0001: begin
						decode4<=7'b1000000;
						decode3<=7'b1111001;
						end
					8'b0010: begin
						decode4<=7'b1000000;
						decode3<=7'b0100100;
						end
					8'b0011: begin
						decode4<=7'b1000000;
						decode3<=7'b0101111;
						end
					8'b0100: begin
						decode4<=7'b1000000;
						decode3<=7'b0011001;
						end
					8'b0101: begin
						decode4<=7'b1000000;
						decode3<=7'b0010010;
						end
					8'b0110: begin
						decode4<=7'b1000000;
						decode3<=7'b0000010;
						end
					8'b0111: begin
						decode4<=7'b1000000;
						decode3<=7'b1111000;
						end
					8'b1000: begin
						decode4<=7'b1000000;
						decode3<=7'b0000000;
						end
					8'b1001: begin
						decode4<=7'b1000000;
						decode3<=7'b0010000;
						end
					8'b1010: begin
						decode4<=7'b1111001;
						decode3<=7'b1000000;
						end
					8'b1011: begin
						decode4<=7'b1111001;
						decode3<=7'b1111001;
						end
					default: begin
						decode4<=7'b1000000;
						decode3<=7'b1000000;
						end
				endcase
end

endmodule

测试代码:
module tbpingp;
reg clk, reset;
reg push1, push0;
wire[6:0] led, decode1, decode2, decode3, decode4;
wire clk_out;

initial
begin
	clk=0;
	reset=0;
	#10 reset=1;
	#20 reset=0;
end

always #5 clk=~clk;

initial
begin
	push1=0;push0=0;
	#40 push1=1;
	#10 push1=0;
	repeat (7) @(posedge clk);
	push0=1;
	#20 push0=0;
	repeat (3) @(posedge clk);
	push1=1;
	#10 push1=0;
	#30 ;
	@(posedge clk);
	#5 push1=1;
	#10 push1=0;
	#100 $stop;
end

pingp pingpang(clk, reset, push1, push0, led, decode1, decode2, decode3,
decode4, clk_out);

endmodule
8.软件下载网站:
1.复制这段内容后打开百度网盘App,操作更方便哦。 链接:https://pan.baidu.com/s/1ZT0ovNAAZ_j3jTGzVCYfbQ
提取码:5jf2
2.复制这段内容后打开百度网盘App,操作更方便哦。 链接:https://pan.baidu.com/s/1bkD2-5Gwl1HB6y9hkUF14A 提取码:540y

上一篇:表单重置type=“file“的input、form.reset用法


下一篇:数电单人实验第六次