Thermostat
module top_module (
input too_cold,
input too_hot,
input mode,
input fan_on,
output heater,
output aircon,
output fan
);
// 控制加热器
assign heater = mode & too_cold;
// 控制空调
assign aircon = ~mode & too_hot;
// 控制风扇
assign fan = (heater | aircon) | fan_on;
endmodule
以下是一些测试用例,验证逻辑是否正确:
mode |
too_cold |
too_hot |
fan_on |
heater |
aircon |
fan |
---|---|---|---|---|---|---|
1 | 1 | 0 | 0 | 1 | 0 | 1 |
1 | 0 | 0 | 0 | 0 | 0 | 0 |
0 | 0 | 1 | 0 | 0 | 1 | 1 |
0 | 0 | 0 | 0 | 0 | 0 | 0 |
0 | 0 | 0 | 1 | 0 | 0 | 1 |
1 | 1 | 0 | 1 | 1 | 0 | 1 |