PS2键盘控制文件3个,在黑金板子上运行,本意是按一下A后4个LED灯亮灭,但是实际情况是按了CAPS LOCK闪烁,右边的SHIFT闪烁,其他按键没反映,请教高手是什么原因,谢谢
********************************ps2顶层文件****************************************************
module ps2_top(
input clk,
input rstn,
input ps2_clk,
input ps2_data,
output reg[3:0]led
);
wire [7:0]data_out;
ps2_neg u1(
.clk(clk),
.rstn(rstn),
.ps2_clk(ps2_clk),
.neg_sig(neg_sig)
);
ps2_decode u2(
.clk(clk),
.rstn(rstn),
.ps2_data(ps2_data),
.neg_sig(neg_sig),
.data_out(data_out)
);
always@(posedge clk or negedge rstn)
if(!rstn==1)
begin
led<=4'b1111;
end else
begin
if(data_out==8'h1c)
begin
led<=~led;
end else
begin
led<=led;
end
end
endmodule
*******************************ps2解码文件********************************************************
module ps2_decode(
input clk,
input rstn,
input ps2_data,
input neg_sig,
output reg[7:0]data_out,
output reg done
);
reg[3:0]cnt_data;
always@(posedge clk or negedge rstn)
if(!rstn==1)
begin
cnt_data<=0;
end else
begin
if(cnt_data==4'd11)
begin
cnt_data<=0;
end else
begin
if(neg_sig==1)
begin
cnt_data<=cnt_data+1'b1;
end
end
end
always@(posedge clk or negedge rstn)
if(!rstn==1)
begin
data_out<=8'b0;
done<=0;
end else
begin
case(cnt_data)
4'd2 :data_out[0]<=ps2_data;
4'd3 :data_out[1]<=ps2_data;
4'd4 :data_out[2]<=ps2_data;
4'd5 :data_out[3]<=ps2_data;
4'd6 :data_out[4]<=ps2_data;
4'd7 :data_out[5]<=ps2_data;
4'd8 :data_out[6]<=ps2_data;
4'd9 :data_out[7]<=ps2_data;
default data_out<=8'b0;
endcase
end
endmodule
************************************ps2下降沿判断文件********************************
module ps2_neg(
input clk,
input rstn,
input ps2_clk,
output neg_sig
);
reg neg_pre;
reg neg_now;
always@(posedge clk or negedge rstn)
if(!rstn)
begin
neg_pre<=1;
neg_now<=1;
end else
begin
neg_now<=ps2_clk;
neg_pre<=neg_now;
end
assign neg_sig=(neg_pre&(!neg_now))?1'b1:1'b0;
endmodule
已退回1积分