programa que multiplica 2 numeros de 4 bits el resultado es mostrado por los display de 7 segmentos tarjeta utilizada basys 2
El codigo en vhdl es el siguiente
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.Std_logic_arith.all;
use IEEE.std_logic_unsigned.all;
use IEEE.numeric_std.all;
entity bcd is
Port ( clr,mclk : in STD_LOGIC;
punto : out std_logic;
a,x : in std_logic_vector (3 downto 0);
y : out std_logic_vector (3 downto 0);
c : out STD_LOGIC_VECTOR (7 downto 0);
d : out STD_LOGIC_VECTOR (6 downto 0));
end bcd;
architecture Behavioral of bcd is
signal b : STD_LOGIC_VECTOR (7 downto 0);
signal unidades,decenas,centenas,sal : STD_LOGIC_VECTOR (3 downto 0);
signal clk2 : std_logic;
signal qq : STD_LOGIC_VECTOR (10 downto 0);
signal count : STD_LOGIC_VECTOR (1 downto 0);
begin
process(a,x,clr)
begin
if clr = '1' then
b <= x"00";
else
b <= (a*x);
end if;
end process;
--**********convertidor binario a bcd para vizualizar en 3 display unidades decenas centanas**********
process(
variable z: STD_LOGIC_VECTOR (19 downto 0);
begin
for i in 0 to 19 loop
z(i) := '0';
end loop;
z(10 downto 3) := B;
for i in 0 to 4 loop
if z(11 downto 8) > 4 then
z(11 downto 8) := z(11 downto 8) + 3;
end if;
if z(15 downto 12) > 4 then
z(15 downto 12) := z(15 downto 12) + 3;
end if;
z(19 downto 1) := z(18 downto 0);
end loop;
unidades <= z(19 downto 16);
decenas <= z(15 downto 12);
centenas <= z(11 downto 8);
end process ;
process(mclk) begin
if rising_edge(mclk) then
qq <= qq + 1;
end if;
end process;
clk2 <= qq(10);
--***********bcd a 7 segmentos**********
process(sal) begin
case sal is
when X"0" => d <= "0000001"; --0
when X"1" => d <= "1001111"; --1
when X"2" => d <= "0010010"; --2
when X"3" => d <= "0000110"; --3
when X"4" => d <= "1001100"; --4
when X"5" => d <= "0100100"; --5
when X"6" => d <= "0100000"; --6
when X"7" => d <= "0001101"; --7
when X"8" => d <= "0000000"; --8
when others => d <= "0000100"; --9
end case;
end process;
--***************multiplexion del display***********
process(count,unidades,decenas,centenas,clk2)
begin
if rising_edge(clk2) then
count <= count + 1;
if count = "11" then
count <= "00";
end if;
end if;
case count is
when "00" => sal <= unidades;
y <= x"b";
when "01" => sal <= decenas;
y <= x"d";
when others => sal <= centenas;
y <= x"e";
end case;
end process;
punto <= '1';
c <=b;
end Behavioral;