强烈建议大家去看看HDLBits 中文导学,原文在知乎
链接: link.
1. Zero
要求输出0;考察了Quartus中,不给变量赋值默认值为0;
模块声明语句中不需要加分号;
//赋0
module top_module(
output zero
);
assign zero=0;
//或者assign zero=1'b0;
endmodule
2. Wire
wire是一种Verilog的数据类型;代表信号;一个输入,多个输出;
assign A=B; //连续赋值
Tips:与软件编程语言不同的是,这里A ,B是动态的,A始终等于B,并且随着B的改变而改变
module top_module( input in, output out );
assign out=in;
endmodule
类似一个黑盒,只需要将输入赋值给输出就行;
3.Wire4
声明的顺序没有影响,Verilog并行执行;
input a;
//其实是
input wire a;
默认省略 wire;
module top_module (
input a, b, c,
output w, x, y,z );
assign w = a;
assign x = b;
assign y = b;
assign z = c;
endmodule
4. Notgate
~:逐位取反;位宽与输入一致
!: 逻辑取反;仅一位
module top_module( input in, output out );
assign out=!in;
endmodule
5. Andgate
&:逐位与
&&:逻辑与
module top_module(
input a,
input b,
output out );
assign out = a & b;
endmodule
6.Norgate
或非门:或门的输出取反
module top_module(
input a,
input b,
output out );
assign out=~(a|b);
endmodule
7.Xnorgate
同或门:相同为1,不同为0;
异或门:相同为0 ,不同为 1;
^:异或符号;
//同或门
module top_module(
input a,
input b,
output out );
assign out= ~(a^b);
endmodule
8.Wire Declaring
模块的输入输出信号wire在模块中声明;
模块中要用到的中间过渡的信号;在模块外声明;
module top_module(
input a,
input b,
input c,
input d,
output out,
output out_n );
wire A1,A2;
assign A1=a&b;
assign A2=c&d;
assign out=A1|A2;
assign out_n=~(A1|A2);
endmodule
9.7458
module top_module (
input p1a, p1b, p1c, p1d, p1e, p1f,
output p1y,
input p2a, p2b, p2c, p2d,
output p2y );
assign p2y=(p2a & p2b)|(p2c & p2d);
assign p1y=(p1a & p1b & p1c)|(p1f & p1e & p1d);
endmodule
本文介绍了Verilog语言中的基本门电路(包括Not, And, Nor, Xor门),Wire数据类型及其用法,以及如何声明和连接电路。详细讲解了Quartus中的默认值设定和7458集成块的使用。适合初学者了解数字逻辑设计的底层原理。
1756

被折叠的 条评论
为什么被折叠?



