library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
entity Div_27Mhz_to_1Hz is
port( clk:in std_logic; clk_out:out std_logic);
end Div_27Mhz_to_1Hz;
architecture div_behavior of Div_27Mhz_to_1Hz is
begin
process(clk)
variable cnt : integer range 0 to 27000000;
begin
if(clk'event and clk = '1')
then
if(cnt >= 13500000)
then
clk_out <= '1';
else
clk_out <= '0';
end if;
if(cnt = 27000000)
then
cnt := 0;
else
cnt := cnt + 1;
end if;
end if;
end process;
end div_behavior;
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
-- For CONV_STD_LOGIC_VECTOR:
use ieee.std_logic_arith.all;
entity cnt_0_to_59 is
port( clk:in std_logic; c59:out std_logic; vector:out std_logic_vector(5 downto 0));
end cnt_0_to_59;
architecture cnt_behavior of cnt_0_to_59 is
begin
process(clk)
variable cnt : integer range 0 to 59;
begin
if(clk'event and clk = '1')
then
if(cnt = 59)
then
cnt := 0;
c59 <= '1';
vector <= CONV_STD_LOGIC_VECTOR(cnt, 6);
else
cnt := cnt + 1;
c59 <= '0';
vector <= CONV_STD_LOGIC_VECTOR(cnt, 6);
end if;
end if;
end process;
end cnt_behavior;
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
-- For CONV_STD_LOGIC_VECTOR:
use ieee.std_logic_arith.all;
entity cnt_0_to_23 is
port( clk:in std_logic; vector:out std_logic_vector(4 downto 0));
end cnt_0_to_23;
architecture cnt_behavior of cnt_0_to_23 is
begin
process(clk)
variable cnt : integer range 0 to 23;
begin
if(clk'event and clk = '1')
then
if(cnt = 23)
then
cnt := 0;
vector <= CONV_STD_LOGIC_VECTOR(cnt, 5);
else
cnt := cnt + 1;
vector <= CONV_STD_LOGIC_VECTOR(cnt, 5);
end if;
end if;
end process;
end cnt_behavior;
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
-- For CONV_STD_LOGIC_VECTOR:
use ieee.std_logic_arith.all;
entity bin2bcd_5bit is
port( bin:in std_logic_vector(4 downto 0);
bcd1:out std_logic_vector(3 downto 0);
bcd10:out std_logic_vector(3 downto 0)
);
end bin2bcd_5bit;
architecture converter_behavior of bin2bcd_5bit is
begin
process(bin)
variable i : integer range 0 to 23;
variable i1 : integer range 0 to 9;
begin
i := conv_integer(bin);
i1 := i / 10;
bcd10 <= CONV_STD_LOGIC_VECTOR(i1, 4);
i1 := i rem 10;
bcd1 <= CONV_STD_LOGIC_VECTOR(i1, 4);
end process;
end converter_behavior;
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
entity BCD_to_7seg is
port(
BCD:in std_logic_vector(3 downto 0);
seg:out std_logic_vector(6 downto 0)
);
end BCD_to_7seg;
architecture conv_behavior of BCD_to_7seg is
begin
process(BCD)
begin
if BCD = "0000" then seg <= "0000001";--0
elsif BCD = "0001" then seg <= "1001111";--1
elsif BCD = "0010" then seg <= "0010010";--2
elsif BCD = "0011" then seg <= "0000110";--3
elsif BCD = "0100" then seg <= "1001100";--4
elsif BCD = "0101" then seg <= "0100100";--5
elsif BCD = "0110" then seg <= "0100000";--6
elsif BCD = "0111" then seg <= "0001111";--7
elsif BCD = "1000" then seg <= "0000000";--8
elsif BCD = "1001" then seg <= "0000100";--9
else seg <= "1001001";--err
end if;
end process;
end conv_behavior;
Source: https://habr.com/ru/post/80056/