我有以下任务,但有些当我使用任务时,它没有给我正确的数字输出,我已经尝试不使用任务,它给了我正确的输出。任何人都能看出我有什么不对吗?
例如,当显示(17,hex3)时,两者都显示全部关闭,而不是全部关闭和数字'1'。
我正在使用7段为4位,hex [6:0],1为关闭。
output reg [6:0] hex3, hex2, hex1, hex0
task display;
input [5:0] num;
output hex;
reg hex;
begin
case(num) // 6543210
if(hex==hex3) begin
0:hex3 =7'b1000000; //0
1:hex3 =7'b1111001; //1
2:hex3 =7'b0100100; //2
3:hex3 =7'b0110000; //3
4:hex3 =7'b0011001; //4
5:hex3 =7'b0010010; //5
6:hex3 =7'b0000010; //6
7:hex3 =7'b1111000; //7
8:hex3 =7'b0000000; //8
9:hex3 =7'b0011000; //9
10:hex3 =7'b0001000; //A
11:hex3 =7'b0000011; //b
12:hex3 =7'b1000110; //C
13:hex3 =7'b0100001; //d
14:hex3 =7'b0000110; //E
15:hex3 =7'b0000111; //F
16:hex3 =7'b0010000; //g
17:hex3 =7'b1111111; //Off
18:hex3 =7'b0001001; //H
endcase
end
else if(hex==hex2) begin
case(num)
0:hex3 =7'b1000000; //0
1:hex2 =7'b1111001; //1
2:hex2 =7'b0100100; //2
3:hex2 =7'b0110000; //3
4:hex2 =7'b0011001; //4
5:hex2 =7'b0010010; //5
6:hex2 =7'b0000010; //6
7:hex2 =7'b1111000; //7
8:hex2 =7'b0000000; //8
9:hex2 =7'b0011000; //9
10:hex2 =7'b0001000; //A
11:hex2 =7'b0000011; //b
12:hex2 =7'b1000110; //C
13:hex2 =7'b0100001; //d
14:hex2 =7'b0000110; //E
15:hex2 =7'b0000111; //F
16:hex2 =7'b0010000; //g
17:hex2 =7'b1111111; //Off
18:hex2 =7'b0001001; //H
endcase
end
endtask
//final
always @(*) begin
if(init) begin
display(17,hex3);
display(1,hex2);
end
end
答案 0 :(得分:0)
input num;
上面的代码意味着1位输入。你需要这个更宽,4位来控制0到F.如果你需要其他状态如OFF,你需要至少5位。
你应该添加一个默认情况,也可能是关闭,然后你不需要完全描述未使用的状态。
//...
default: hex =7'b1111111;
endcase