-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchoose_pattern.v
49 lines (45 loc) · 1.3 KB
/
choose_pattern.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
module choose_pattern(clk, rst, keypadRow, keypadCol, pattern, draw);
input clk, rst;
input [3:0] keypadCol;
output reg draw;
output reg [3:0] keypadRow, pattern;
always @(posedge clk or negedge rst) begin
if (!rst) begin
keypadRow <= 4'b1110;
pattern <= 4'h1;
draw <= 0;
end
else begin
case ({keypadRow, keypadCol})
8'b0111_0111: pattern <= 4'hf;
8'b0111_1011: pattern <= 4'he;
8'b0111_1101: pattern <= 4'hd;
8'b0111_1110: pattern <= 4'hc;
8'b1011_0111: pattern <= 4'hb;
8'b1011_1011: pattern <= 4'h3;
8'b1011_1101: pattern <= 4'h6;
8'b1011_1110: pattern <= 4'h9;
8'b1101_0111: pattern <= 4'ha;
8'b1101_1011: pattern <= 4'h2;
8'b1101_1101: pattern <= 4'h5;
8'b1101_1110: pattern <= 4'h8;
8'b1110_0111: pattern <= pattern;
8'b1110_1011: pattern <= 4'h1;
8'b1110_1101: pattern <= 4'h4;
8'b1110_1110: pattern <= 4'h7;
default: pattern <= pattern;
endcase
case ({keypadRow, keypadCol})
8'b1110_0111: draw <= 1;
default: draw <= 0;
endcase
case (keypadRow)
4'b0111: keypadRow <= 4'b1011;
4'b1011: keypadRow <= 4'b1101;
4'b1101: keypadRow <= 4'b1110;
4'b1110: keypadRow <= 4'b0111;
default: keypadRow <= 4'b1110;
endcase
end
end
endmodule