首页 | 新闻 | 新品 | 文库 | 方案 | 视频 | 下载 | 商城 | 开发板 | 数据中心 | 座谈新版 | 培训 | 工具 | 博客 | 论坛 | 百科 | GEC | 活动 | 主题月 | 电子展
返回列表 回复 发帖

fpga实列3

fpga实列3

实验 5
8
3优先编码器module encoder(d0,d1,d2,d3,d4,d5,d6,d7,x,y,v);
output x,y,v;
input d0,d1,d2,d3,d4,d5,d6,d7;
reg x,y,v;
always @ (d0 or d1 or d2 or d3 or d4 or d5 or d6 or d7)
if (d7 == 0)
{x,y,v} = 3'b111 ;
else if (d6 == 0)
{x,y,v} = 3'b110 ;
else if (d5 == 0)
{x,y,v} = 3'b101 ;
else if (d4 == 0)
{x,y,v} = 3'b100 ;
else if (d3 == 0)
{x,y,v} = 3'b011 ;
else if (d2 == 0)
{x,y,v} = 3'b010 ;
else if (d1 == 0)
{x,y,v} = 3'b001 ;
else if (d0 == 0)
{x,y,v} = 3'b000 ;
else
{x,y,v} = 3'bxxx ;
endmodule
实验6
十—二进制编码器// decimal to binary encoder
module encoder(y,a);
output [4:0] y;
input [4:0] a; // input [4] 为十位,[3:0]为个位 ?
reg [4:0] y;
always @ (a)
// A
是敏感信号

begin

if(a>9)


y<=a-6;
//
这里完成了十进制到二进制的编码,


else


y<=a;

end
//为了方便在平台上进行观察验证

///这里把数据的个位用 4 2 进制数据表示,十位用 1bit 进行显示;
endmodule
实验 7
三选一数据选择器module mux3to1(dout,a,b,c,sel);
output[1:0] dout;
input [1:0] a,b,c;
input[1:0] sel;
reg [1:0] dout;
// RTL
modeling

always @(a or b or c or sel)
case(sel)
2'b00 : dout<=a;
2'b01 : dout<=b;
2'b10 : dout<=c;
default :dout<=2'bx;
endcase
endmodule
实验 8
半加器//数据流方式描述的 1 位半加器
module halfadder (sum,cout,a,b);
input a,b;
output sum,cout;
assign sum=a^b;
assign cout=a&b;// carry out;
endmodule
附录:各种不同的描述方式:
1,调用门元件实现的1 位半加器
module half_add1(a,b,sum,cout);
input a,b;
output sum,cout;
and (cout,a,b);
xor (sum,a,b);
endmodule
2,采用行为描述的1
位半加器

module half_add3(a,b,sum,cout);
input a,b;
output sum,cout;
reg sum,cout;
always @(a or b)
begincase ({a,b}) //真值表描述
2'b00: begin sum=0; cout=0; end
2'b01: begin sum=1; cout=0; end
2'b10: begin sum=1; cout=0; end
2'b11: begin sum=0; cout=1; end
endcase
end
endmodule
3,采用行为描述的1
位半加器

module half_add4(a,b,sum,cout);
input a,b;
output sum,cout;
reg sum,cout;
always @(a or b)
begin
sum= a^b;
cout=a&b;
end
endmodule
返回列表