Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- library IEEE;
- use IEEE.STD_LOGIC_1164.ALL;
- use IEEE.STD_LOGIC_ARITH.ALL;
- use IEEE.STD_LOGIC_UNSIGNED.ALL;
- entity projekt7 is
- port (
- start_stop_button_i: in STD_LOGIC;
- clk_i: in STD_LOGIC;
- rst_i: in STD_LOGIC;
- led7_an_o: out STD_LOGIC_VECTOR (3 downto 0);
- led7_seg_o: out STD_LOGIC_VECTOR (7 downto 0)
- );
- end projekt7;
- architecture behavioral of projekt7 is
- component projekt6noinput
- port (
- clk_i: in std_logic;
- rst_i: in std_logic;
- led7_an_o: out std_logic_vector(3 downto 0) := "0000";
- digit_i: in std_logic_vector(31 downto 0);
- led7_seg_o: out std_logic_vector(7 downto 0)
- );
- end component;
- component projekt5noreset
- port (
- clk_i : in std_logic;
- clk_o : out std_logic
- );
- end component;
- signal timer_start: std_logic := '0';
- signal timer_stop: std_logic := '0';
- signal clk_o: std_logic;
- signal digit_i: std_logic_vector (31 downto 0) := "00000011000000100000001100000011";
- type time_array is array (0 to 4) of integer range 0 to 10;
- signal cur_time: time_array := (others => 0);
- --signal vibs: integer range 0 to 2;
- function seg(data: integer range 0 to 9) return std_logic_vector is
- begin
- case data is
- when 0 => return ("0000001"); -- 0
- when 1 => return ("1001111"); -- 1
- when 2 => return ("0010010"); -- 2
- when 3 => return ("0000110"); -- 3
- when 4 => return ("1001100"); -- 4
- when 5 => return ("0100100"); -- 5
- when 6 => return ("0100000"); -- 6
- when 7 => return ("0001111"); -- 7
- when 8 => return ("0000000"); -- 8
- when 9 => return ("0000100"); -- 9
- when others => return ("0000001"); -- 0
- end case;
- end function seg;
- function seg_time(data: time_array) return std_logic_vector is
- variable temp : std_logic_vector(31 downto 0);
- begin
- if (data(4) = 6) then
- temp := "11111101111111001111110111111101";
- else
- temp(0) := '1';
- temp(8) := '1';
- temp(16) := '0';
- temp(24) := '1';
- temp(7 downto 1) := seg(data(1));
- temp(15 downto 9) := seg(data(2));
- temp(23 downto 17) := seg(data(3));
- temp(31 downto 25) := seg(data(4));
- end if;
- return temp;
- end function seg_time;
- begin
- projekt5: projekt5noreset port map (clk_i => clk_i, clk_o => clk_o);
- projekt6: projekt6noinput port map (clk_i => clk_i, rst_i => rst_i, led7_an_o => led7_an_o, led7_seg_o => led7_seg_o, digit_i => digit_i);
- --process(clk_o)
- -- variable counter: integer := 0;
- -- begin
- -- if(rising_edge(clk_o)) then
- -- if(start_stop_button_i = '1') then
- -- vibs <= 0;
- -- counter := counter + 1;
- -- else
- -- if(counter > 50) then
- -- if(vibs = 2) then
- -- vibs <= 0;
- -- else
- -- vibs <= vibs + 1;
- -- end if;
- -- end if;
- -- counter := 0;
- -- end if;
- -- end if;
- --end process;
- process (clk_o, rst_i)
- begin
- if (rst_i = '1') then
- cur_time(0) <= 0;
- cur_time(1) <= 0;
- cur_time(2) <= 0;
- cur_time(3) <= 0;
- cur_time(4) <= 0;
- elsif (rising_edge(clk_o)) then
- if (start_stop_button_i = '1') then
- if (timer_start = '0' and timer_stop = '0') then -- and vibs = 1
- timer_start <= '1';
- elsif (timer_start = '1' and timer_stop = '0') then
- timer_stop <= '1';
- elsif (timer_start = '1' and timer_stop = '1') then
- timer_start <= '0';
- timer_stop <= '0';
- end if;
- end if;
- if (timer_start = '0' and timer_stop = '0') then
- cur_time(0) <= 0;
- cur_time(1) <= 0;
- cur_time(2) <= 0;
- cur_time(3) <= 0;
- cur_time(4) <= 0;
- end if;
- if (timer_start = '1' and timer_stop = '0') then
- cur_time(0) <= cur_time(0) + 1;
- if (cur_time(0) = 9) then
- cur_time(0) <= 0;
- cur_time(1) <= cur_time(1) + 1;
- end if;
- if (cur_time(1) = 10) then
- cur_time(1) <= 0;
- cur_time(2) <= cur_time(2) + 1;
- end if;
- if (cur_time(2) = 10) then
- cur_time(2) <= 0;
- cur_time(3) <= cur_time(3) + 1;
- end if;
- if (cur_time(3) = 10) then
- cur_time(3) <= 0;
- cur_time(4) <= cur_time(4) + 1;
- end if;
- if (cur_time(4) = 6) then
- timer_stop <= '1';
- end if;
- end if;
- end if;
- end process;
- digit_i <= seg_time(cur_time);
- end Behavioral;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement