Prev Problem
Next Problem

72. 7-Segment Display Decoder

Back To All Submissions
Previous Submission
Next Submission

Solving Approach

How do you plan to solve it?

 

Code

// /*Write your code here*/
module sevenseg_hex(
    input [3:0] hex,
    output [6:0] seg
);
    parameter a = 10,b = 11,c = 12,d = 13,e = 14,f = 15;

assign seg[6] = hex == 0 | hex == 2 | hex == 3 | hex == 5 | hex == 6 | hex == 7 | hex == 8 | hex == 9 | hex == a | hex == c | hex == e | hex == f;
assign seg[5] = hex == 0 | hex == 1 | hex == 2 | hex == 3 | hex == 4 | hex == 7 | hex == 8 | hex == 9 | hex == a | hex == d;
assign seg[4] = hex == 0 | hex == 1 | hex == 3 | hex == 4 | hex == 5 | hex == 6 | hex == 7 | hex == 8 | hex == 9 | hex == a | hex == b | hex == d;
assign seg[3] = hex == 0 | hex == 2 | hex == 3 | hex == 5 | hex == 6 | hex == 8 | hex == 9 | hex == b | hex == c | hex == d | hex == e;
assign seg[2] = hex == 0 | hex == 2 | hex == 6 | hex == 8 | hex > 9;
assign seg[1] = hex == 0 | hex == 4 | hex == 5 | hex == 6 | hex == 8 | hex == 9 | hex == a | hex == b | hex == c | hex == e | hex == f;
assign seg[0] = hex == 2 | hex == 3 | hex == 4 | hex == 5 | hex == 6 | hex == 8 | hex == 9 | hex == a | hex == b | hex == d | hex == e | hex == f;

endmodule

// module sevenseg_hex (
//     input  [3:0] hex,
//     output reg [6:0] seg   // {a,b,c,d,e,f,g}, ACTIVE-HIGH
// );
//     always @* begin
//         case (hex)
//             4'h0: seg = 7'b1111110; // a b c d e f
//             4'h1: seg = 7'b0110000; // b c
//             4'h2: seg = 7'b1101101; // a b   d e   g
//             4'h3: seg = 7'b1111001; // a b c d     g
//             4'h4: seg = 7'b0110011; //   b c     f g
//             4'h5: seg = 7'b1011011; // a   c d   f g
//             4'h6: seg = 7'b1011111; // a   c d e f g
//             4'h7: seg = 7'b1110000; // a b c
//             4'h8: seg = 7'b1111111; // a b c d e f g
//             4'h9: seg = 7'b1111011; // a b c d   f g
//             4'hA: seg = 7'b1110111; // a b c   e f g
//             4'hB: seg = 7'b0011111; //     c d e f g  (looks like 'b')
//             4'hC: seg = 7'b1001110; // a       d e f
//             4'hD: seg = 7'b0111101; //   b c d e   g  (looks like 'd')
//             4'hE: seg = 7'b1001111; // a       d e f g
//             4'hF: seg = 7'b1000111; // a         e f g
//             default: seg = 7'b0000000; // blank
//         endcase
//     end
// endmodule

 

Was this helpful?
Upvote
Downvote