很久之前,数电实验课要求使用Verilog编程并在nexys4的板子上实现相应的功能。现在把实验课用过的代码放到上面。
用三种方法实现取反加一
取反加一十分简单,每一种方法基本上都是一两句话能完成
1.数据流建模
module qfjy(
input [3:0]a,
output [3:0]b
);
assign b=~a+1;
endmodule
2.门级电路
module qfjy2(input [3:0]a,output [3:0]b);
or(b[0],a[0]);
xor(b[1],a[0],a[1]);
wire c,d;
or(c,a[0],a[1]);
xor(b[2],a[2],c);
or(d,c,a[2]);
xor(b[3],a[3],d);
endmodule
门级电路的实现需要画真值表卡诺图再去找输入输出对应关系
3.行为级建模
module qfjy3(input [3:0]a,output reg [3:0]b);
always@(a) begin
b<=~a+1;
end
endmodule
使用nexys4板子的led灯来显示其功能,并使用“落后的”ise进行编程
引脚约束(只能在ise上能这样用,vivado不是这样的格式)
# PlanAhead Generated physical constraints
NET "a[0]" LOC = U9;
# PlanAhead Generated IO constraints
NET "a[3]" IOSTANDARD = LVCMOS33;
NET "a[2]" IOSTANDARD = LVCMOS33;
NET "a[1]" IOSTANDARD = LVCMOS33;
NET "a[0]" IOSTANDARD = LVCMOS33;
# PlanAhead Generated physical constraints
NET "a[0]" LOC = U9;
NET "a[1]" LOC = U8;
NET "a[2]" LOC = R7;
NET "a[3]" LOC = R6;
NET "b[0]" LOC = T8;
NET "b[1]" LOC = V9;
NET "b[2]" LOC = R8;
NET "b[3]" LOC = T6;
# PlanAhead Generated IO constraints
NET "b[3]" IOSTANDARD = LVCMOS33;
NET "b[2]" IOSTANDARD = LVCMOS33;
NET "b[1]" IOSTANDARD = LVCMOS33;
NET "b[0]" IOSTANDARD = LVCMOS33;
以上就是Verilog取反加一的全部内容