quertus2实现全减器、奇偶校验电路、8421非法码检测,以及相关其他

74LS20芯片

module my74LS20(a,b,c,d,out1);

input a,b,c,d;	
output out1;   
assign out1 =~(a&b&c&d);
endmodule

74LS138芯片

module my74LS138(eab,sw,out);

input [2:0] eab; 
input [2:0] sw;
output [7:0] out;

reg [7:0] out;

always @ (sw or eab)
	begin
	if(eab<3'b100)
		out=8'b1111_1111;
	else 
		case(sw)
			3'b000:	out=8'b0111_1111;
			3'b001:	out=8'b1011_1111;                     
			3'b010:	out=8'b1101_1111;
			3'b011:	out=8'b1110_1111;
			3'b100:	out=8'b1111_0111;
			3'b101:	out=8'b1111_1011;
			3'b110: 	out=8'b1111_1101;
			3'b111:	out=8'b1111_1110;
			default: ;
		endcase
	end

endmodule

74LS139芯片

module my74LS139(eab,sw,out);

input eab; 
input [1:0] sw;
output [3:0] out;

reg [3:0] out;

always @ (sw or eab)
	begin
	if(eab>0)
		out=4'b1111;
	else 
		case(sw)
			2'b00:	out=8'b0111;
			2'b01:	out=8'b1011;                     
			2'b10:	out=8'b1101;
			2'b11:	out=8'b1110;
			default: ;
		endcase
	end

endmodule

74LS151芯片

module my74LS151(eab,sw,in,out_Y,out_W);

input eab; 
input [2:0] sw;
input [7:0] in;
output out_Y,out_W; 

reg out_Y,out_W;
always @ (sw or eab or in)
	begin
	if(eab>0)
		begin 
		out_W=1;
		out_Y=0;
		end
	else 
	begin
		case(sw)
			3'b000:	
				begin
				out_Y=in[0]; 
				out_W=!in[0];
				end
			3'b001:	
				begin
				out_Y=in[1]; 
				out_W=!in[1];
				end
			3'b010:	
				begin
				out_Y=in[2]; 
				out_W=!in[2];
				end
			3'b011:	
				begin
				out_Y=in[3]; 
				out_W=!in[3];
				end
			3'b100:	
				begin
				out_Y=in[4]; 
				out_W=!in[4];
				end
			3'b101:	
				begin
				out_Y=in[5]; 
				out_W=!in[5];
				end
			3'b110: 	
				begin 
				out_Y=in[6]; 
				out_W=!in[6];
				end
			3'b111:	
				begin
				out_Y=in[7]; 
				out_W=!in[7];
				end
			default: ;
		endcase
	end
	end

endmodule

74LS283芯片

module my74LS283(in_A,in_B,c_0,out,c_4);

input [3:0] in_A; 
input [3:0] in_B;
input c_0;
output [3:0] out;
output c_4;

reg [3:0] out;
reg c_4;
reg [31:0]cnt;
reg temp_G,temp_P,temp_K;
reg [3:0] tem_C;

always @ (in_A or in_B or c_0)
	begin
	for(cnt=0;cnt<=3;cnt=cnt+1)
	begin
		temp_G=in_A[cnt]*in_B[cnt];
		temp_P=in_A[cnt]+in_B[cnt];
		temp_K=in_A[cnt]^in_B[cnt];
		if(cnt==0)
		begin
			out[cnt]=temp_K^c_0;
			tem_C[cnt]=temp_G+temp_P*c_0;
		end
		else
		begin
			out[cnt]=temp_K^tem_C[cnt-1];
			tem_C[cnt]=temp_G+temp_P*tem_C[cnt-1];	
		end
	end
	c_4 = tem_C[3];
	end

endmodule

全减器:

module myor(in,C_0,out_Y);

input [2:0] in;
output C_0;
output out_Y;

wire [7:0] out;

my74LS138 u0(3'b100,in,out);
my74LS20 u1(out[1],out[2],out[3],out[7],C_0);
my74LS20 u2(out[1],out[2],out[4],out[7],out_Y);

endmodule 

    testbench:

initial                                                
begin                                                  
in=3'b000;
#100 in=3'b001;      
#100 in=3'b010; 
#100 in=3'b100; 
#100 in=3'b011; 
#100 in=3'b101; 
#100 in=3'b110; 
#100 in=3'b111;                                    
$display("Running testbench");                       
end        

奇偶校验电路:

module myor(in_0_1,in_2,out_1,out_2);

input [1:0]in_0_1;
input in_2;
output out_1,out_2;

wire [3:0] temp1;
wire [3:0] temp2;

my74LS139 u0(~in_2,in_0_1,temp1);
my74LS139 u1(in_2,in_0_1,temp2);

my74LS20 u2(temp1[0],temp1[3],temp2[1],temp2[2],out_1);
my74LS20 u3(temp2[0],temp2[3],temp1[1],temp1[2],out_2);
endmodule

    testbench:

initial                                                
begin                                                  
in_0_1=2'b00;in_2=0;
#100 in_0_1=2'b00;in_2=1;   
#100 in_0_1=2'b01;in_2=0; 
#100 in_0_1=2'b01;in_2=1; 
#100 in_0_1=2'b10;in_2=0; 
#100 in_0_1=2'b10;in_2=1; 
#100 in_0_1=2'b11;in_2=0; 
#100 in_0_1=2'b11;in_2=1;                           
$display("Running testbench");                       
end        

8421BCD 非法码检测:

module myor(in,out_data);

input [2:0] in;
output out_data;

wire temp_0,temp_1,temp_2;
wire out_1;
wire [2:0] in_data;

assign in_data[2:0]=in[2:0];
my74LS151 u0(0,in_data,8'b11100000,out_data,out_2);


endmodule

    testbench:

initial                                                
begin                                                  
in=2'b000;
#100 in=2'b001;  
#100 in=2'b010;
#100 in=2'b100;
#100 in=2'b101;
#100 in=2'b011;
#100 in=2'b110;  
#100 in=2'b111;                                         
$display("Running testbench");                       
end        

8421BCD 码转余3BCD 码:

module myor(in_B,out,c);

input [3:0] in_B;
output [3:0] out;
output c;
wire [3:0] in_A= 4'b0011;

my74LS283 u0(in_A,in_B,(1'b0),out,c);
	
endmodule 

    testbench:

initial                                                
begin                                                  
in_B=4'b0000;
#100 in_B=4'b0001;   
#100 in_B=4'b0010; 
#100 in_B=4'b0011; 
#100 in_B=4'b0100; 
#100 in_B=4'b0101; 
#100 in_B=4'b0110; 
#100 in_B=4'b0111; 
#100 in_B=4'b1000;    
#100 in_B=4'b1001;                                               
$display("Running testbench");                       
end                                    

二位二进制数相乘:

module myor(in_A,in_B,out);

input [1:0] in_A;
input [1:0] in_B;
output [3:0] out;

assign out[0] = in_A[0]*in_B[0];
assign out[1] = (in_A[1]*(~in_A[0])*in_B[0])|((~in_A[1])*in_A[0]*in_B[1])|(in_A[1]*(~in_B[1])*in_B[0])|(in_A[0]*in_B[1]*(~in_B[0]));
assign out[2] = (in_A[1]*(~in_A[0])*in_B[1])|(in_A[1]*in_B[1]*(~in_B[0]));
assign out[3] = in_A[1]*in_A[0]*in_B[1]*in_B[0];

endmodule

    testbench:

initial                                                
begin                                                  
in_A=2'b00;in_B= 2'b00;
#100 in_A=2'b00;in_B= 2'b01; 
#100 in_A=2'b00;in_B= 2'b10;  
#100 in_A=2'b00;in_B= 2'b11;  
#100 in_A=2'b01;in_B= 2'b00;  
#100 in_A=2'b01;in_B= 2'b01;  
#100 in_A=2'b01;in_B= 2'b10;  
#100 in_A=2'b01;in_B= 2'b11;  
#100 in_A=2'b10;in_B= 2'b00;  
#100 in_A=2'b10;in_B= 2'b01; 
#100 in_A=2'b10;in_B= 2'b10;  
#100 in_A=2'b10;in_B= 2'b11;  
#100 in_A=2'b11;in_B= 2'b00;  
#100 in_A=2'b11;in_B= 2'b01;  
#100 in_A=2'b11;in_B= 2'b10;  
#100 in_A=2'b11;in_B= 2'b11;                                        
$display("Running testbench");                       
end    

 

  • 0
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值