这里写自定义目录标题
Verilog编程巩固
1.在线Verilog编程网站学习
1.1 门电路
1.1.1 与门
编写代码
module top_module(
input a,
input b,
output out );
assign out=a&b;
endmodule
仿真结果
1.1.2 非门
编写代码
module top_module( input in, output out );
assign out=~in;
endmodule
仿真结果
1.1.3 同或门
编写代码
module top_module(
input a,
input b,
output out );
assign out= !((!a & b) | (a & !b));
endmodule
仿真结果
1.2 组合电路
1.2.1 半加器
编写代码
module top_module(
input a, b,
output cout, sum );
assign cout=a&b;
assign sum=a^b;
endmodule
仿真结果
1.2.2 全加器
编写代码
module top_module(
input a, b, cin,
output cout, sum );
assign sum = a^b^cin;
assign cout = (a&b)|(a&cin)|(b&cin);
endmodule
仿真结果
1.2.3 2选1多路复用器
编写代码
module top_module(
input a, b, sel,
output out );
assign out=(sel)?b:a;
endmodule
仿真结果
1.3 时序电路
1.3.1 D触发器
编写代码
2.编写代码
module top_module (
input clk, // Clocks are used in sequential circuits
input d,
output reg q );//
// Use a clocked always block
// copy d to q at every positive edge of clk
// Clocked always blocks should use non-blocking assignments
always@(posedge clk) begin
q <= d;
end
endmodule
仿真结果
1.3.2 8位D触发器
编写代码
module top_module (
input clk,
input [7:0] d,
output [7:0] q
);
always@(posedge clk) begin
q <= d;
end
endmodule
仿真结果
1.3.3 锁存器
编写代码
module top_module (
input d,
input ena,
output q);
always@(*)begin
if(ena)begin
q<=d;
end
end
endmodule
仿真结果
出现警告,可能是锁存器比较消耗资源的原因。
2.安装 Robei 软件
[下载地址](http : //robei.com/software/Robei3.5.5.zip)