输出接地
module top_module (
output out);
assign out = 1'b0;
endmodule
out_anotb: a and-not b
module top_module (
input in1,
input in2,
output out);
assign out = in1 &~ in2;
endmodule
常用门电路汇总
- out_and: a and b
- out_or: a or b
- out_xor: a xor b
- out_nand: a nand b
- out_nor: a nor b
- out_xnor: a xnor b
- out_anotb: a and-not b
module top_module(
input a, b,
output out_and,
output out_or,
output out_xor,
output out_nand,
output out_nor,
output out_xnor,
output out_anotb
);
assign out_and = a & b;
assign out_or = a | b;
assign out_xor = a ^b;
assign out_nand = ~(a & b);
assign out_nor = ~(a | b);
assign out_xnor = a ~^ b;
assign out_anotb = a &~ b;
endmodule
Ringer
Suppose you are designing a circuit to control a cellphone's ringer and vibration motor. Whenever the phone needs to ring from an incoming call (input ring
), your circuit must either turn on the ringer (output ringer = 1
) or the motor (output motor = 1
), but not both. If the phone is in vibrate mode (input vibrate_mode = 1
), turn on the motor. Otherwise, turn on the ringer.
Try to use only assign
statements, to see whether you can translate a problem description into a collection of logic gates.
module top_module(
input ring,
input vibrate_mode,
output ringer,
output motor
);
// When should ringer be on? When (phone is ringing) and (phone is not in vibrate mode)
assign ringer = ring & ~vibrate_mode;
// When should motor be on? When (phone is ringing) and (phone is in vibrate mode)
assign motor = ring & vibrate_mode;
endmodule
Thermostat
A heating/cooling thermostat controls both a heater (during winter) and an air conditioner (during summer). Implement a circuit that will turn on and off the heater, air conditioning, and blower fan as appropriate.
The thermostat can be in one of two modes: heating (mode = 1
) and cooling (mode = 0
). In heating mode, turn the heater on when it is too co