BCD to 7-segment display
converter:
An Electronic display
device used for for displaying decimal numbers is called 7-segment
display (SSD).
A Seven-segment
display (SSD) has seven segments and theoretically it can display 27 i-e 128 combinations of characters.
fpga verilog code example
Here is an example of
Verilog code for a BCD (Binary-Coded Decimal) to 7-segment display converter:
Seven segment display
Code:
//Verilog module.
module segment7(
bcd,
seg
);
//Declare inputs,outputs and internal variables.
input [3:0] bcd;
output [6:0] seg;
reg [6:0] seg;
//always block for
conversion of BCD digits into 7-segment format
always @(bcd)
begin
case (bcd) //case statement
0 : seg = 7'b0000001;
1 : seg = 7'b1001111;
2 : seg = 7'b0010010;
3 : seg = 7'b0000110;
4 : seg = 7'b1001100;
5 : seg = 7'b0100100;
6 : seg = 7'b0100000;
7 : seg = 7'b0001111;
8 : seg = 7'b0000000;
9 : seg = 7'b0000100;
//switch off 7-segment characters when the BCD digits are
not decimal numbers.
default : seg = 7'b1111111;
endcase
end
endmodule
Testbench:
module tb_segment7;
reg [3:0] bcd;
wire [6:0] seg;
integer i;
// incarnate the Unit Under Test (UUT)
segment7 uut (
.bcd(bcd),
.seg(seg)
);
//Apply inputs
initial begin
for(i = 0;i < 16;i = i+1) //run loop for 0 to 15.
begin
bcd = i;
#10; //wait for 10 ns
end
end
endmodule
This code defines a
module called "segment7" that converts a 4-bit BCD input (bcd) to a
7-bit output for a 7-segment display (seg). The BCD to 7-segment conversion is
done in the always block with the case statement. Each case statement assigns
the output value of the 7-segment display based on the value of the BCD input.
Please note that this is
just a basic example, and the actual code will depend on the specific
requirements of your application, the type of 7-segment display you are using
and the type of BCD input you are using.
The output will be the
segments of the 7-segment display. The seven segment displays are common
cathode or common anode, so the outputs will be inverted in case of common
cathode or not inverted if it is common anode.
No comments:
Post a Comment