Modelsim仿真实现Verilog HDL投票表决器

假设共有7个人投票,只能投赞成或反对票,只要有4人或4人以上的赞成票,就视为通过,否则视为不通过。

  • 输入为a, b, c, d, e, f, g,共7个布尔量。用随机数对2取余生成激励。
  • 输出为out,1个布尔量。

主程序:

module voting(a, b, c, d, e, f, g, out);
	input a, b, c, d, e, f, g;
	output wire out;
assign out = ((a + b + c + d + e + f + g)>=4) ? 1:0;
endmodule

测试程序:

`timescale 1 ns/ 1 ns
module tb_voting();
	reg a, b, c, d, e, f, g;
	wire out;
voting U3(.a(a), .b(b), .c(c), .d(d), .e(e), .f(f), .g(g), .out(out));
initial begin
	repeat(5) begin
	a = $random % 2;
	b = $random % 2;
	c = $random % 2;
	d = $random % 2;
	e = $random % 2;
	f = $random % 2;
	g = $random % 2;
	#10;
	end
end
endmodule

结果如下:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值