FPGA 09 基础 3 -8 、 4-16 译码器实验

在这里插入图片描述

FPGA 学习 09 基础 3 -8 、 4-16 译码器实验

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-coac9Ads-1627394484961)(img/blog_img/fpga/image-20210719153856097.png)]

模块名称: decoder_3_8 decoder_4_16

主要功能 :将一个 3位二进制的数转换位10进制的 8位输出 (4进制的二进制数转换为16进制的 16位输出)

实现(设计)流程: 内部使用组合逻辑实现,使用case 语句完成逻辑电平的输出.

  • decoder_3_8.v 文件
module decoder_3_8(a,b,c,out);

	input a ;	//输入端口 A
	input b ;	//输入端口 B
	input c ;	//输入端口 C
	
	output reg [7:0]out; //输出端口 out
	
	always@(a,b,c)
	begin
		case({a,b,c})
			3'b000: out = 8'b0000_0001 ; //使用 = 赋值,必须要是reg的类型,否则无法赋值
			3'b001: out = 8'b0000_0010 ;
			3'b010: out = 8'b0000_0100 ;
			3'b011: out = 8'b0000_1000 ;
			3'b100: out = 8'b0001_0000 ;
			3'b101: out = 8'b0010_0000 ;
			3'b110: out = 8'b0100_0000 ;
			3'b111: out = 8'b1000_0000 ;
			default : out=8'b1111_1111 ;
		endcase
	end

endmodule



  • decoder_3_8_tb. v 文件
`timescale 1ns/1ns

module decoder_3_8_tb ;

//测试时, input --> reg
// output --> wire
	reg a;
	reg b;
	reg c;

	wire [7:0]out;
	
	decoder_3_8 decoder_3_8_U1(
	
	.a(a),
	.b(b),
	.c(c),
	.out(out)
	);
	
	initial begin 
	#200 ;
	
	a=0 ;b=0 ; c=0 ;	
	#200 ;
	a=0 ;b=0 ; c=1 ;	
	#200 ;
	a=0 ;b=1 ; c=0 ;	
	#200 ;
	a=0 ;b=1 ; c=1 ;	
	#200 ;
	
	a=1 ;b=0 ; c=0 ;	
	#200 ;
	a=1 ;b=0 ; c=1 ;	
	#200 ;
	a=1 ;b=1 ; c=0 ;	
	#200 ;
	a=1 ;b=1 ; c=1 ;	
	#200 ;

	$stop ;
	
	end
	

endmodule


decoder_4_16.v

module decoder_4_16(
	
	a,
	b,
	c,
	d,
	
	out
);

	input a ;
	input b ;
	input c ;	
	input d ;
	
	output reg [15:0]out ;
	
	always@(a,b,c,d)
	begin
		case ({a,b,c,d})
		4'b0000: out =16'b0000_0000_0000_0001 ;
		4'b0001: out =16'b0000_0000_0000_0010 ;
		4'b0010: out =16'b0000_0000_0000_0100 ;
		4'b0011: out =16'b0000_0000_0000_1000 ;
		
		4'b0100: out =16'b0000_0000_0001_0000 ;
		4'b0101: out =16'b0000_0000_0010_0000 ;
		4'b0110: out =16'b0000_0000_0100_0000 ;
		4'b0111: out =16'b0000_0000_1000_0000 ;
		
		4'b1000: out =16'b0000_0001_0000_0000 ;
		4'b1001: out =16'b0000_0010_0000_0000 ;
		4'b1010: out =16'b0000_0100_0000_0000 ;
		4'b1011: out =16'b0000_1000_0000_0000 ;

		4'b1100: out =16'b0001_0000_0000_0000 ;
		4'b1101: out =16'b0010_0000_0000_0000 ;
		4'b1110: out =16'b0100_0000_0000_0000 ;
		4'b1111: out =16'b1000_0000_0000_0000 ;
		default: out =16'h_ffff ;
		endcase
	end 
endmodule




decoder_4_16_tb.v 文件

`timescale 1ns/1ns
module decoder_4_16_tb;

	reg a ;
	reg b ;
	reg c ;
	reg d ;
	
	wire [15:0]out ;

	 decoder_4_16 decoder_4_16_u1(
	 
		.a(a),
		.b(b),
		.c(c),
		.d(d),
		
		.out(out)
	);

	initial begin
		#200;
		
		a=0 ;b=0 ; c=0 ;	d= 0;
		#200 ;
		a=0 ;b=0 ; c=0 ;	d= 1;
		#200 ;
		a=0 ;b=0 ; c=0 ;	d= 0;
		#200 ;
		a=0 ;b=0 ; c=1 ;	d= 1;
		#200 ;
		
		a=0 ;b=1 ; c=0 ;	d= 0;
		#200 ;
		a=0 ;b=1 ; c=0 ;	d= 1;
		#200 ;
		a=0 ;b=1 ; c=0 ;	d= 0;
		#200 ;
		a=0 ;b=1 ; c=1 ;	d= 1;
		#200 ;
		
		a=1 ;b=0 ; c=0 ;	d= 0;
		#200 ;
		a=1 ;b=0 ; c=0 ;	d= 1;
		#200 ;
		a=1 ;b=0 ; c=0 ;	d= 0;
		#200 ;
		a=1 ;b=0 ; c=1 ;	d= 1;
		#200 ;

		a=1 ;b=1 ; c=0 ;	d= 0;
		#200 ;
		a=1 ;b=1 ; c=0 ;	d= 1;
		#200 ;
		a=1 ;b=1 ; c=0 ;	d= 0;
		#200 ;
		a=1 ;b=1 ; c=1 ;	d= 1;
		#200 ;
		
		$stop ;
	
	end

endmodule



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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值