-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPS2Receiver.v
More file actions
85 lines (73 loc) · 1.76 KB
/
PS2Receiver.v
File metadata and controls
85 lines (73 loc) · 1.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
// courtesy of Digilent https://github.com/Digilent/Nexys-A7-50T-Keyboard
`timescale 1ns / 1ps
//////////////////////////////////////////////////////////////////////////////////
// Company: Digilent Inc.
// Engineer: Thomas Kappenman
//
// Create Date: 03/03/2015 09:33:36 PM
// Design Name:
// Module Name: PS2Receiver
// Project Name: Nexys4DDR Keyboard Demo
// Target Devices: Nexys4DDR
// Tool Versions:
// Description: PS2 Receiver module used to shift in keycodes from a keyboard plugged into the PS2 port
//
// Dependencies:
//
// Revision:
// Revision 0.01 - File Created
// Additional Comments:
//
//////////////////////////////////////////////////////////////////////////////////
module PS2Receiver(
input clk,
input kclk,
input kdata,
output [31:0] keycodeout
);
wire kclkf, kdataf;
reg [7:0]datacur;
reg [7:0]dataprev;
reg [3:0]cnt;
reg [31:0]keycode;
reg flag;
initial begin
keycode[31:0]<=0'h00000000;
cnt<=4'b0000;
flag<=1'b0;
end
debouncer debounce(
.clk(clk),
.I0(kclk),
.I1(kdata),
.O0(kclkf),
.O1(kdataf)
);
always@(negedge(kclkf))begin
case(cnt)
0:;//Start bit
1:datacur[0]<=kdataf;
2:datacur[1]<=kdataf;
3:datacur[2]<=kdataf;
4:datacur[3]<=kdataf;
5:datacur[4]<=kdataf;
6:datacur[5]<=kdataf;
7:datacur[6]<=kdataf;
8:datacur[7]<=kdataf;
9:flag<=1'b1;
10:flag<=1'b0;
endcase
if(cnt<=9) cnt<=cnt+1;
else if(cnt==10) cnt<=0;
end
always @(posedge flag)begin
if (dataprev!=datacur)begin
keycode[31:24]<=keycode[23:16];
keycode[23:16]<=keycode[15:8];
keycode[15:8]<=dataprev;
keycode[7:0]<=datacur;
dataprev<=datacur;
end
end
assign keycodeout=keycode;
endmodule