Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- `timescale 1ns/1ps
- module SevenSegmentController(
- input [31:0] ms_count, // Millisecond count input
- output reg [6:0] hex0, // 7-segment output for digit 0 (LSB)
- output reg [6:0] hex1, // 7-segment output for digit 1
- output reg [6:0] hex2, // 7-segment output for digit 2
- output reg [6:0] hex3, // 7-segment output for digit 3
- output reg [6:0] hex4, // 7-segment output for digit 4
- output reg [6:0] hex5 // 7-segment output for digit 5 (MSB)
- );
- // Local variables for extracted digits
- reg [3:0] digit[5:0];
- // 7-segment encoding (active low):
- // a-g segments for digits 0-9
- function [6:0] encode;
- input [3:0] value;
- case (value)
- 4'd0: encode = 7'b1000000; // 0
- 4'd1: encode = 7'b1111001; // 1
- 4'd2: encode = 7'b0100100; // 2
- 4'd3: encode = 7'b0110000; // 3
- 4'd4: encode = 7'b0011001; // 4
- 4'd5: encode = 7'b0010010; // 5
- 4'd6: encode = 7'b0000010; // 6
- 4'd7: encode = 7'b1111000; // 7
- 4'd8: encode = 7'b0000000; // 8
- 4'd9: encode = 7'b0010000; // 9
- default: encode = 7'b1111111; // Blank
- endcase
- endfunction
- // Extract digits from ms_count
- always @(*) begin
- // Convert ms_count into individual digits (BCD extraction)
- digit[0] = ms_count % 10;
- digit[1] = (ms_count / 10) % 10;
- digit[2] = (ms_count / 100) % 10;
- digit[3] = (ms_count / 1000) % 10;
- digit[4] = (ms_count / 10000) % 10;
- digit[5] = (ms_count / 100000) % 10;
- // Map digits to corresponding 7-segment displays
- hex0 = encode(digit[0]);
- hex1 = encode(digit[1]);
- hex2 = encode(digit[2]);
- hex3 = encode(digit[3]);
- hex4 = encode(digit[4]);
- hex5 = encode(digit[5]);
- end
- endmodule
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement