tags:
- verilog
- formulation
created: 2024-10-23
This seven-segment decoder takes four 4-bit numbers as input, a
, b
, c
, and d
. It outputs a segment pattern representing one of those for 4-bit numbers using a 4-bit selector signal, anode
. The available patterns for the segments range from 0 to 15 in hexadecimal. This would control a seven-segment display with four anodes, or representable digits, like a seven-segment alarm clock.
module seven_segment_decoder(
input [3:0] a,
input [3:0] b,
input [3:0] c,
input [3:0] d,
input [3:0] anode,
output reg [6:0] segments
);
reg [3:0] selected;
always @(*) begin
case (anode)
'b1110: selected <= a;
'b1101: selected <= b;
'b1011: selected <= c;
'b0111: selected <= d;
default: selected <= 4'bx;
endcase
end
always @(*) begin
case(selected)
// GFEDCBA
0: segments = 7'b1000000;
1: segments = 7'b1111001;
2: segments = 7'b0100100;
3: segments = 7'b0110000;
4: segments = 7'b0011001;
5: segments = 7'b0010010;
6: segments = 7'b0000010;
7: segments = 7'b1111000;
8: segments = 7'b0000000;
9: segments = 7'b0010000;
10: segments = 7'b0001000;
11: segments = 7'b0000011;
12: segments = 7'b1000110;
13: segments = 7'b0100001;
14: segments = 7'b0000110;
15: segments = 7'b0001110;
endcase
end
endmodule