用红、黄、绿三个指示灯表示三台设备的工作情况:绿灯亮表示全部正常;红灯亮表示有一台不正常,黄灯亮表示两台不正常;红、黄灯全亮表示三台都不正常,设备正常用1表示,设备不正常用0表示;灯亮用1表示,灯灭用0表示。用Verilog HDL编程实现上述功上述功能并给出独立的测试文件
时间: 2024-06-01 11:12:21 浏览: 10
module indicator_lights(input wire [2:0] status, output reg [2:0] lights);
always @(*)
begin
case(status)
3'b000: lights = 3'b001; // all devices working
3'b001: lights = 3'b100; // one device not working
3'b010: lights = 3'b010; // one device not working
3'b011: lights = 3'b110; // two devices not working
3'b100: lights = 3'b001; // one device not working
3'b101: lights = 3'b100; // two devices not working
3'b110: lights = 3'b010; // two devices not working
3'b111: lights = 3'b111; // all devices not working
endcase
end
endmodule
// Testbench
module indicator_lights_tb;
reg [2:0] status;
wire [2:0] lights;
indicator_lights dut(.status(status), .lights(lights));
initial begin
$monitor("status = %b, lights = %b", status, lights);
status = 3'b000; // all devices working
#10 status = 3'b001; // one device not working
#10 status = 3'b010; // one device not working
#10 status = 3'b011; // two devices not working
#10 status = 3'b100; // one device not working
#10 status = 3'b101; // two devices not working
#10 status = 3'b110; // two devices not working
#10 status = 3'b111; // all devices not working
#10 $finish;
end
endmodule
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)