Altera_Forum
Honored Contributor
13 years ago8bits to 7segments decoder
Hi, im trying to make a 8bits to 3digits 7segments decoder usind a double dabble, but there is something wrong with my code and i dont know what, can you help me?
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
package my_pkg is
function to_bcd (bin : std_logic_vector(7 downto 0)) return std_logic_vector;
end package my_pkg;
package body my_pkg is
function to_bcd (bin : std_logic_vector(7 downto 0)) return std_logic_vector is
variable i : integer:=0;
variable bcd : std_logic_vector(11 downto 0) := (others => '0');
variable bint : std_logic_vector(7 downto 0) := bin;
begin
for i in 0 to 7 loop
bcd(11 downto 1) := bcd(10 downto 0);
bcd(0) := bint(7);
bint(7 downto 1) := bint(6 downto 0);
bint(0) :='0';
if(i < 7 and bcd(3 downto 0) > "0100") then
bcd(3 downto 0) := bcd(3 downto 0) + "0011";
end if;
if(i < 7 and bcd(7 downto 4) > "0100") then
bcd(7 downto 4) := bcd(7 downto 4) + "0011";
end if;
if(i < 7 and bcd(11 downto 8) > "0100") then
bcd(11 downto 8) := bcd(11 downto 8) + "0011";
end if;
end loop;
return bcd;
end to_bcd;
end package body my_pkg;
entity termometro is
port (
clk: in std_logic;
data: in std_logic_vector(7 downto 0);
Di: out std_logic_vector (6 downto 0);
Vtc:out std_logic_vector(3 downto 0));
end termometro;
architecture behavior of termometro is
signal bcd1, bcd2, bcd3: std_logic_vector(3 downto 0);
type segs is(se0, se1, se2);
signal seg_atual, prox_seg: segs;
signal S1, S2, S3: std_logic_vector(6 downto 0);
begin
bcd1<=to_bcd(3 downto 0);
bcd2<=to_bcd(7 downto 4);
bcd3<=to_bcd(11 downto 7);
process(bcd1, bcd2, bcd3)
begin
WITH bcd1 SELECT
S1 <= "1111110" when "0000",
"0110000" when "0001",
"1101101" when "0010",
"1111001" when "0011",
"0110011" when "0100",
"1011011" when "0101",
"0100000" when "0110",
"1110000" when "0111",
"1111111" when "1000",
"1111011" when "1001",
"0000000" when others;
WITH bcd2 SELECT
S1 <= "1111110" when "0000",
"0110000" when "0001",
"1101101" when "0010",
"1111001" when "0011",
"0110011" when "0100",
"1011011" when "0101",
"0100000" when "0110",
"1110000" when "0111",
"1111111" when "1000",
"1111011" when "1001",
"0000000" when others;
WITH bcd3 SELECT
S1 <= "1111110" when "0000",
"0110000" when "0001",
"1101101" when "0010",
"1111001" when "0011",
"0110011" when "0100",
"1011011" when "0101",
"0100000" when "0110",
"1110000" when "0111",
"1111111" when "1000",
"1111011" when "1001",
"0000000" when others;
end process;
process(clk) is
begin
if(clk = '1' and clk'event) then
seg_atual<=prox_seg;
end if;
end process;
process (S1, S2, S3) is
begin
case seg_atual is
when se0=>
Di <= S1;
Vtc<= "0001";
prox_seg <= se1;
when se1 =>
Di <= S2;
Vtc<= "0010";
prox_seg <= se2;
when se2 =>
Di <= S3";
Vtc<= "0100";
prox_seg <= se3;
end case;
end process;
end behavior;