-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathseven_seg.v
72 lines (65 loc) · 1.52 KB
/
seven_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
67
68
69
70
71
72
// Cause yosys to throw an error when we implicitly declare nets
`default_nettype none
// Seven segment controller
// Switches quickly between the two parts of the display
// to create the illusion of both halves being illuminated
// at the same time.
module seven_seg_ctrl (
input CLK,
input [7:0] din,
output reg [7:0] dout
);
wire [6:0] lsb_digit;
wire [6:0] msb_digit;
seven_seg_hex msb_nibble (
.din(din[7:4]),
.dout(msb_digit)
);
seven_seg_hex lsb_nibble (
.din(din[3:0]),
.dout(lsb_digit)
);
reg [9:0] clkdiv = 0;
reg clkdiv_pulse = 0;
reg msb_not_lsb = 0;
always @(posedge CLK) begin
clkdiv <= clkdiv + 1;
clkdiv_pulse <= &clkdiv;
msb_not_lsb <= msb_not_lsb ^ clkdiv_pulse;
if (clkdiv_pulse) begin
if (msb_not_lsb) begin
dout[6:0] <= ~msb_digit;
dout[7] <= 0;
end else begin
dout[6:0] <= ~lsb_digit;
dout[7] <= 1;
end
end
end
endmodule
// Convert 4bit numbers to 7 segments
module seven_seg_hex (
input [3:0] din,
output reg [6:0] dout
);
always @*
case (din)
4'h0: dout = 7'b 0111111;
4'h1: dout = 7'b 0000110;
4'h2: dout = 7'b 1011011;
4'h3: dout = 7'b 1001111;
4'h4: dout = 7'b 1100110;
4'h5: dout = 7'b 1101101;
4'h6: dout = 7'b 1111101;
4'h7: dout = 7'b 0000111;
4'h8: dout = 7'b 1111111;
4'h9: dout = 7'b 1101111;
4'hA: dout = 7'b 1110111;
4'hB: dout = 7'b 1111100;
4'hC: dout = 7'b 0111001;
4'hD: dout = 7'b 1011110;
4'hE: dout = 7'b 1111001;
4'hF: dout = 7'b 1110001;
default: dout = 7'b 1000000;
endcase
endmodule