-
Notifications
You must be signed in to change notification settings - Fork 1
/
kbctrl.v
62 lines (58 loc) · 1.21 KB
/
kbctrl.v
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
`timescale 1ns / 1ps
//////////////////////////////////////////////////////////////////////////////////
// Company:
// Engineer:
//
// Create Date: 22:21:16 01/04/2014
// Design Name:
// Module Name: kbctrl
// Project Name:
// Target Devices:
// Tool versions:
// Description:
//
// Dependencies:
//
// Revision:
// Revision 0.01 - File Created
// Additional Comments:
//
//////////////////////////////////////////////////////////////////////////////////
module kbctrl(input KCLK, input KDATA, output [7:0] KCODE, output KCOME);
reg enable;
reg [3:0] left, right;
reg [31:0] count;
reg is_start;
reg [8:0] shift;
assign KCODE = {left, right};
assign KCOME = enable;
initial
begin
enable = 0;
left = 4'd0;
right = 4'd0;
count = 32'd0;
is_start = 0;
shift = 9'd0;
end
always @(posedge KCLK)
begin
enable = 0;
left[3:0] = 4'd0;
right[3:0] = 4'd0;
if(is_start == 0 && KDATA == 0) begin
is_start = 1;
end
else if(is_start==1) begin
shift = {KDATA, shift[8:1]};
count = count + 1;
if(count>=9) begin
count = 0;
is_start = 0;
enable = 1;
left[3:0] = shift[7:4];
right[3:0] = shift[3:0];
end
end
end
endmodule