ring or vibrate?

题目如下:

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 (), your circuit must either turn on the ringer () or the motor (), but not both. If the phone is in vibrate mode (), turn on the motor. Otherwise, turn on the ringer. input ringoutput ringer = 1output motor = 1input vibrate_mode = 1

代码如下:

module top_module (
    input ring,
    input vibrate_mode,
    output ringer,       // Make sound
    output motor         // Vibrate
);
    assign ringer=(ring==1'b1&&vibrate_mode==1'b0)?1'b1:1'b0;
    assign motor=(ring==1'b1&&vibrate_mode==1'b1)?1'b1:1'b0;
endmodule

评价:
不知道是不是自己的理解能力欠缺,这道题如果不读懂它的意思,还是会觉得文字上有一些绕
总结一下,这个题目意思是首先判断ring是否响应,响应了说明有人找,理解为手机有来电,但是有来电,是表现为有铃声还是震动,再来一个与逻辑判断
这个题目做的就是这个事情

posted @ 2024-03-07 17:33  江左子固  阅读(13)  评论(0)    收藏  举报