THIS BLOG POST WAS UPDATED ON 4th Mar 2024!
7-segment displays are commonly used in FPGA (Field-Programmable Gate Array) boards for displaying numeric and sometimes alphanumeric information. These displays consist of seven individual LED segments arranged in a pattern that can display numerals from 0 to 9, as well as some letters such as A-F for hexadecimal displays.
To show a certain character using the 7 segment display, you need to lit up the corresponding segments. This is done by not passing a voltage to it, basically driving it with a '0' signal in VHDL.
The following image shows how the numbers from 0 to 9 can be displayed using a 7 segment display.
If you want a decimal number of higher than 9 to be displayed using this code, then convert the decimal number into BCD and then instantiate this module for each digit in the BCD code.
The following VHDL code can be used to convert bcd digits into 7 bit std_logic_vector signals which can be used to show the correct digits on the display piece. Note that, a in the above picture corresponds to MSB of segment7 and g corresponds to LSB of segment7.
VHDL Entity:
library IEEE; use IEEE.STD_LOGIC_1164.ALL; use IEEE.NUMERIC_STD.ALL; entity seven_segment_decoder is port ( bcd : in unsigned(3 downto 0); --BCD input -- 'a' corresponds to MSB of segment7 and g corresponds to LSB of segment7. segment7 : out std_logic_vector(6 downto 0) -- 7 bit decoded output. ); end seven_segment_decoder; architecture Behavioral of seven_segment_decoder is begin process (bcd) BEGIN case bcd is when "0000"=> segment7 <="0000001"; -- '0' when "0001"=> segment7 <="1001111"; -- '1' when "0010"=> segment7 <="0010010"; -- '2' when "0011"=> segment7 <="0000110"; -- '3' when "0100"=> segment7 <="1001100"; -- '4' when "0101"=> segment7 <="0100100"; -- '5' when "0110"=> segment7 <="0100000"; -- '6' when "0111"=> segment7 <="0001111"; -- '7' when "1000"=> segment7 <="0000000"; -- '8' when "1001"=> segment7 <="0000100"; -- '9' --nothing is displayed when a number more than 9 is given as input. when others=> segment7 <="1111111"; end case; end process; end Behavioral;
Testbench:
Here is a sample test bench code for this module:
LIBRARY ieee; USE ieee.std_logic_1164.ALL; use IEEE.NUMERIC_STD.ALL; ENTITY tb_seg7_decoder IS END tb_seg7_decoder; ARCHITECTURE behavior OF tb_seg7_decoder IS signal bcd : unsigned(3 downto 0) := (others => '0'); signal segment7 : std_logic_vector(6 downto 0); BEGIN --entity port mapping. Usiong uut: entity work.seven_segment_decoder PORT MAP (bcd => bcd, segment7 => segment7); stim_proc: process begin -- apply an input bcd digit and wait for 100 ns -- so that we can check the output in the waveform. for i in 0 to 9 loop bcd <= to_unsigned(i,4); wait for 100 ns; end loop; end process; END;
hello.. can you pls post a test bench for this code.. tnx...
ReplyDelete@Alfred : I have modified the post including the test bench.Hope that helps..
ReplyDeletetnx a lot..
ReplyDeletethank you, it is so useful for me.
ReplyDeleteCan you show me, how to control a animation on vga using keyboard in vhdl
Hi, I'm trying to implement the sum of two numbers with 5 bits and show in two digits SSD, but with no success, do you have any idea how to do this?
ReplyDeleteI had success with decimal counter until 99, but how make this work whit the sum, I don't know.
Thanks
Can some one help me with the code for Four bit BCD decimal COUNTER using VHDL and the 74LS90. I'm using Xilinx 12.1 and I'm really struggling with the logic gate code.
ReplyDeletemy email is jct0378@gmail.com
Please help me!
ReplyDeleteWrite a VHDL code to perform the function of multiplier
which the inputs are from Dip Switch and outputs
display to 7-segment LED with BCD.
X : dip 1~4represents value 0~15
Y : dip 5~8represents value 0~15
Thanks you so much
write a VHDL prog to display number on BCD-7 segment display , input given from ps/2 keyboard
ReplyDeletecan you help me to get a VHBL program for 64 bit CSA
ReplyDeleteCan you post the synthesis report.
ReplyDeleteHi, need help can you please provide me the VHDL codes for "SN74LS247" which is BCD 2 7-segment decoder/driver similar to one mention above but it has 3 additional logic and no clock.
ReplyDeleteplz help me or u can send me code on desai335@yahoo.com.
This will be really appreciated.
can you post code for multiplexed display
ReplyDeletecan anyone send me the project which consists ASIC design that are using synthesis tool and VHDL code. I'm new from this field can anyone send overall view to design the project. what the companies can do regarding ASIC design (overall) send to email address arun.distinctive@gmail.com
ReplyDeleteplease send it asap............and overall project
In reply to @Bhaumik:
ReplyDeletelibrary IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity SN74LS247 is
Port ( BCD_I : in STD_LOGIC_VECTOR (3 downto 0);
RBI : in STD_LOGIC;
LT : in STD_LOGIC;
BI : in STD_LOGIC;
RBO : out STD_LOGIC;
SEG_O : out STD_LOGIC_VECTOR (6 downto 0));
end SN74LS247;
architecture Behavioral of SN74LS247 is
signal enable : std_logic;
begin
enable <= LT and BI;
--abcdefg
SEG_O <= "1111110" when (BCD_I = "0000") and enable = '1' and RBI = '1' else -- 0
"0110000" when (BCD_I = "0001") and enable = '1' else -- 1
"1101101" when (BCD_I = "0010") and enable = '1' else -- 2
"1111001" when (BCD_I = "0011") and enable = '1' else -- 3
"0110011" when (BCD_I = "0100") and enable = '1' else -- 4
"1011011" when (BCD_I = "0101") and enable = '1' else -- 5
"1011111" when (BCD_I = "0110") and enable = '1' else -- 6
"1110000" when (BCD_I = "0111") and enable = '1' else -- 7
"1111111" when (BCD_I = "1000") and enable = '1' else -- 8
"1111011" when (BCD_I = "1001") and enable = '1' else -- 9
"0001101" when (BCD_I = "1010") and enable = '1' else -- 10
"0011001" when (BCD_I = "1011") and enable = '1' else -- 11
"0100011" when (BCD_I = "1100") and enable = '1' else -- 12
"1001011" when (BCD_I = "1101") and enable = '1' else -- 13
"0001111" when (BCD_I = "1110") and enable = '1' else -- 14
"0000000" when (BCD_I = "1111") and enable = '1' else -- 15
"0000000" when RBI = '0' and LT = '1' and BCD_I = "0000" and BI = '0' else
"0000000" when BI = '0' else
"1111111" when LT = '0' else
"0000000";
RBO <= '1' when LT='1' and RBI='0' and BCD_I="0000" else '0';
end Behavioral;
Urgent...
DeleteI need test bench for this please,
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity SN74LS247 is
Port ( BCD_I : in STD_LOGIC_VECTOR (3 downto 0);
RBI : in STD_LOGIC;
LT : in STD_LOGIC;
BI : in STD_LOGIC;
RBO : out STD_LOGIC;
SEG_O : out STD_LOGIC_VECTOR (6 downto 0));
end SN74LS247;
architecture Behavioral of SN74LS247 is
signal enable : std_logic;
begin
enable <= LT and BI;
--abcdefg
SEG_O <= "1111110" when (BCD_I = "0000") and enable = '1' and RBI = '1' else -- 0
"0110000" when (BCD_I = "0001") and enable = '1' else -- 1
"1101101" when (BCD_I = "0010") and enable = '1' else -- 2
"1111001" when (BCD_I = "0011") and enable = '1' else -- 3
"0110011" when (BCD_I = "0100") and enable = '1' else -- 4
"1011011" when (BCD_I = "0101") and enable = '1' else -- 5
"1011111" when (BCD_I = "0110") and enable = '1' else -- 6
"1110000" when (BCD_I = "0111") and enable = '1' else -- 7
"1111111" when (BCD_I = "1000") and enable = '1' else -- 8
"1111011" when (BCD_I = "1001") and enable = '1' else -- 9
"0001101" when (BCD_I = "1010") and enable = '1' else -- 10
"0011001" when (BCD_I = "1011") and enable = '1' else -- 11
"0100011" when (BCD_I = "1100") and enable = '1' else -- 12
"1001011" when (BCD_I = "1101") and enable = '1' else -- 13
"0001111" when (BCD_I = "1110") and enable = '1' else -- 14
"0000000" when (BCD_I = "1111") and enable = '1' else -- 15
"0000000" when RBI = '0' and LT = '1' and BCD_I = "0000" and BI = '0' else
"0000000" when BI = '0' else
"1111111" when LT = '0' else
"0000000";
RBO <= '1' when LT='1' and RBI='0' and BCD_I="0000" else '0';
end Behavioral;
my email is :
yns69167@gmail.com
15S13544@mec.edu.om
how to i show the otuput of this above program using quartus II
ReplyDeleteplease help me i need vhdl code for mimo using communication system
ReplyDeletei need vhdl coding for mimo using communication system
ReplyDeletehi could you please create a TEST BECH for SN74LS247...
ReplyDeletekindly share the test bech code
Deletehi , is the clock necessary for this code ?
ReplyDeletehi , is the clock necessary for this code ?
ReplyDeletehie can anyone help me to blink an external led using spartan 3e using vhdl
ReplyDeletehelp me, i need vhdl code for counter for atm machine when login more than 3 times its terminate . please urgent :(
ReplyDeleteHi ,,do you know how to do vhdl code for 2 bit x 2 bit multiplier using decoder to seven segment display?? Please please help me..i seriously dont know how to do it.
ReplyDeletehi i need to code 7segment BCD by use if , else. Please help me and thank for answer.
ReplyDeletehow do you display on the 7-segment display and display using the led's to display the binary value at the same time
ReplyDeletedo you have the corresponding XDC file ?
ReplyDeleteIf block diagram of binary to 7segment is given , much easier to understand.
ReplyDeletePlz. If anyone can post the block diagram and vhdl code in behavioural modelling for this .
Can you share UCF File ?
ReplyDelete