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.

代码如下:

module top_module (
    input too_cold,
    input too_hot,
    input mode,
    input fan_on,
    output heater,
    output aircon,
    output fan
); 
    assign heater=(too_cold&&mode)?1'b1:1'b0;
    assign aircon=(too_hot&&!mode)?1'b1:1'b0;
    assign fan=(too_cold&&mode||too_hot&&!mode||fan_on)?1'b1:1'b0;
endmodule

评论:
重点在于写出状态标示图(并非状态转换图),然后按情况assign即可。

posted @ 2024-03-07 18:00  江左子固  阅读(8)  评论(0)    收藏  举报