FPGA 學習 00 二選一多路選擇器

沒有價值的生命發表於2020-10-02

mux2.v

	
module mux2(
//埠列表	
	a,  //key0 1
	b,		//key1 1
	sel,	//key2 1
	out	//1:led熄滅  0: led亮
);

// key1 按下 釋放
// key0 按下 釋放
// key2 按下 
// key1 按下 釋放
// key0 按下 釋放
	
//埠型別定義
	input a;
	input b;
	input sel;
	
	output out;

	assign out = sel? b:a;
//	assign out = (sel == 1)? b:a;

endmodule


mux2_tb.v

`timescale 1ns/1ns

module mux2_tb();
	
	//激勵源
	reg s1;   //a
	reg s2;	//b
	reg s3;	//sel
	
	wire Light1;
	
	mux2 mux2_i0(
	//埠列表	
		.a(s1),
		.b(s2),
		.sel(s3),
		.out(Light1)
	);
	
	initial begin
		s1 = 0;s2 = 0;s3 =0;
		
		#100;
		s1 = 1;s2 = 0;s3 =0;
	
		#100;
		s1 = 0;s2 = 1;s3 =0;
		
		#100;
		
		s1 = 1;s2 = 1;s3 =0;
		#100;
		
		s1 = 0;s2 = 0;s3 =1;
		
		#100;
		s1 = 1;s2 = 0;s3 =1;
	
		#100;
		s1 = 0;s2 = 1;s3 =1;
		
		#100;
		s1 = 1;s2 = 1;s3 =1;
		
		#100;
		
		$stop;
	
	end

	
endmodule



引腳定義:

input a —> key0 --> M16
input b —> key1 --> E15
input sel —> E16
output out; —> A2

相關文章