程序一:
module key(key_r ,key_c ,clk ,key_v);
input [7:0] key_c;
input clk;
output [3:0] key_r;
output [13:0] key_v;
reg [3:0] key_r;
reg [13:0] key_v;
reg [7:0] key_c_old;
reg en_scan ; //这里是程序中将要改动的位置
reg [7:0]delay_cnt;
reg [1:0]scan_cnt;
always @ (posedge clk)
begin
if(en_scan == 1)
key_r <= key_r;
else
begin
scan_cnt <= scan_cnt + 1'b1;
case (scan_cnt)
2'b00: key_r <= 4'b1000;
2'b01: key_r <= 4'b0100;
2'b10: key_r <= 4'b0010;
2'b11: key_r <= 4'b0001;
endcase
end
end
always @(posedge clk)
if(key_c == 9'b111111111)
begin
delay_cnt <= 1'b0;
en_scan <= 1'b0;
end
else
begin
en_scan <= 1'b1;
if(delay_cnt == 2)
begin
key_v <= {2'b10,key_c,key_r};
delay_cnt <= 0;
end
else
delay_cnt <= delay_cnt + 1'b1;
end
endmodule
程序二:
module key(key_r ,key_c ,clk ,key_v);
input [7:0] key_c;
input clk;
output [3:0] key_r;
output [13:0] key_v;
reg [3:0] key_r;
reg [13:0] key_v;
reg [7:0] key_c_old;
reg en_scan = 1'b0 ; //这里是程序中改动的情况
reg [7:0]delay_cnt;
reg [1:0]scan_cnt;
always @ (posedge clk)
begin
if(en_scan == 1)
key_r <= key_r;
else
begin
scan_cnt <= scan_cnt + 1'b1;
case (scan_cnt)
2'b00: key_r <= 4'b1000;
2'b01: key_r <= 4'b0100;
2'b10: key_r <= 4'b0010;
2'b11: key_r <= 4'b0001;
endcase
end
end
always @(posedge clk)
if(key_c == 9'b111111111)
begin
delay_cnt <= 1'b0;
en_scan <= 1'b0;
end
else
begin
en_scan <= 1'b1;
if(delay_cnt == 2)
begin
key_v <= {2'b10,key_c,key_r};
delay_cnt <= 0;
end
else
delay_cnt <= delay_cnt + 1'b1;
end
请问下 谁能给我解释一下:为何程序二编译后用到的LC寄存器(LC Register)是27个,而程序一编译后仅用了16个?请哪位高手来解释下 ,非常感谢!!困惑了好几天了!!
新手:就给个1分,表示一下!
|