wire ps2_clk_risingedge = (ps2_clkr[2:1]==2'b01); // now we can detect ps2_clk rising edges
wire ps2_clk_fallingedge = (ps2_clkr[2:1]==2'b10); // and falling edges
4.当检测到第一个低电平时,我们只需要连续读取11个周期值就可以了,这里用一个变量i来控制
always @(posedge clk)
if(rst)
i <= 0;
else
begin
if(ps2_clk_fallingedge)
begin
data2 <= data;
data <= ps2_data;
if(i<10) i <= i+1;
else i <= 0;
end
end
wire ps2_clk_risingedge = (ps2_clkr[2:1]==2'b01); // now we can detect ps2_clk rising edges
wire ps2_clk_fallingedge = (ps2_clkr[2:1]==2'b10); // and falling edges
always @(posedge clk)
if(rst)
i <= 0;
else
begin
if(ps2_clk_fallingedge)
begin
data2 <= data;
data <= ps2_data;
if(i<10) i <= i+1;
else i <= 0;
end
end