-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdecoder_4_7_seg.v
66 lines (59 loc) · 1.62 KB
/
decoder_4_7_seg.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
module decoder_4_7_seg (
input clk, rst,
input [13:0] displayed_number,
output reg [3:0] digit,
output reg [7:0] segs
);
reg [3:0] bcd;
reg [18:0] counter;
reg [1:0] led_select;
initial begin
counter <= 0;
end
always @(posedge clk, posedge rst) begin
if (rst == 1'b1) begin
counter <= 0;
end else begin
counter <= counter + 1;
end
end
assign led_select = counter[18:17];
always @(led_select) begin
case(led_select)
2'b00: begin
digit = ~4'b0001;
bcd = ((displayed_number % 1000) % 100) % 10;
end
2'b01: begin
digit = ~4'b0010;
bcd = ((displayed_number % 1000) % 100) / 10;
end
2'b10: begin
digit = ~4'b0100;
bcd = (displayed_number % 1000) / 100;
end
2'b11: begin
digit = ~4'b1000;
bcd = displayed_number / 1000;
end
default: begin
digit = ~4'b0000;
end
endcase
end
always @(posedge clk) begin
case (bcd)
0: segs <= ~7'b0111111;
1: segs <= ~7'b0000110;
2: segs <= ~7'b1011011;
3: segs <= ~7'b1001111;
4: segs <= ~7'b1100110;
5: segs <= ~7'b1101101;
6: segs <= ~7'b1111101;
7: segs <= ~7'b0000111;
8: segs <= ~7'b1111111;
9: segs <= ~7'b1101111;
default: segs <= ~7'b0000000;
endcase
end
endmodule