-
Notifications
You must be signed in to change notification settings - Fork 0
/
Store_Hex.v
83 lines (72 loc) · 2.39 KB
/
Store_Hex.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
`timescale 1ns / 1ps
//////////////////////////////////////////////////////////////////////////////////
// Company:
// Engineer:
//
// Create Date: 04/17/2022 04:28:38 PM
// Design Name:
// Module Name: Store_Hex
// Project Name:
// Target Devices:
// Tool Versions:
// Description:
//
// Dependencies:
//
// Revision:
// Revision 0.01 - File Created
// Additional Comments:
//
//////////////////////////////////////////////////////////////////////////////////
//Takes in a 4 bit binary number and stores the number when enter is high, when four 4 bit numbers are entered
//the module then concatenates the 4 numbers into the output password
module Store_Hex(
//Input hex_in takes in a 4 bit binary number representing the position of the switches
input [3:0] hex_in,
//Input reset resets the hex input process by resetting the counter
input reset,
//Input enter stores the current hex_in into hex[i]
input enter,
input enable,
//Output of the 4 hex number inputs as a 16 bit password
output reg [15:0] password,
//hex[i] stores the past inputted hex numbers
output reg [3:0] hex1,hex2,hex3,hex4,
//Counts the number of hex numbers the user has entered, when it reaches 2'b11 and the user presses enter,
//the 4 stored hex numbers are concatenated into password
output reg [1:0] counter
);
reg [15:0] undefined_16bit;
reg [3:0] undefined_hex;
always @(posedge enter or posedge reset)begin
if(reset) begin
counter = 2'b00;
password = undefined_16bit;
hex1 = undefined_hex;
hex2 = undefined_hex;
hex3 = undefined_hex;
hex4 = undefined_hex;
end
else if(enter && enable) begin
case(counter)
2'b00: begin
hex1 = hex_in;
counter = counter + 2'b01;
end
2'b01: begin
hex2 = hex_in;
counter = counter + 2'b01;
end
2'b10: begin
hex3 = hex_in;
counter = counter + 2'b01;
end
2'b11: begin
hex4 = hex_in;
counter = 2'b00;
password = {hex1,hex2,hex3,hex4};
end
endcase
end
end
endmodule