设计内容:若同意人数超过半数时,输出为1。用开关表示输入,用LED灯(自定义)的亮灭表示最终结果。
程序代码:
module toupiao(a,out);
input [6:0]a;
output reg out;
integer i,count1,count2;
always@(*)
begin
count1=0;
count2=0;
i=0;
while(i<7)
begin
if(a[i]==1)
count1=count1+1;
else
count2=count2+1;
i=i+1;
end
if(count1<count2)out=2'b00;
else if(count1>count2)out=2'b01;
end
endmodule
输入程序后,填写对应的引脚,即可