Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- library IEEE;
- use IEEE.STD_LOGIC_1164.ALL;
- use IEEE.NUMERIC_STD.all;
- entity lab is
- Port ( clk,rst, rx : in STD_LOGIC; -- rst är tryckknappen i mitten under displayen
- seg: out UNSIGNED(7 downto 0);
- an : out UNSIGNED (3 downto 0));
- end lab;
- architecture Behavioral of lab is
- component leddriver
- Port ( clk,rst : in STD_LOGIC;
- seg : out UNSIGNED(7 downto 0);
- an : out UNSIGNED (3 downto 0);
- value : in UNSIGNED (15 downto 0));
- end component;
- signal sreg : UNSIGNED(9 downto 0) := B"0_00000000_0"; -- 10 bit skiftregister
- signal tal : UNSIGNED(15 downto 0) := X"0000";
- signal rx1,rx2 : std_logic; -- vippor på insignalen
- signal sp : std_logic; -- skiftpuls
- signal run : std_logic; -- Bestäm om vi ska läsa in ett värde eller inte
- signal lp : std_logic; -- laddpuls
- signal pos : UNSIGNED(1 downto 0) := "00";
- signal bit_counter : UNSIGNED(9 downto 0) := "0000000000";
- signal state_counter : UNSIGNED(3 downto 0) := "0000";
- alias nya_talet: unsigned(3 downto 0) sreg(3 downto 0);
- alias pos0: unsigned(3 downto 0) tal(15 downto 12);
- alias pos1: unsigned(3 downto 0) sreg(11 downto 8);
- alias pos2: unsigned(3 downto 0) sreg(7 downto 4);
- alias pos3: unsigned(3 downto 0) sreg(3 downto 0);
- // vippor
- begin
- process(clk) begin
- if rising_edge(clk) then
- if rst = '1' then
- rx1 <= '1';
- rx2 <= '1';
- else
- rx1 <= rx;
- rx2 <= rx1;
- end if;
- end if;
- end process;
- // skiftregister
- process(clk) begin
- if rising_edge(clk) then
- if rst = '1' then
- sreg <= "0000000000";
- elsif sp = '1' then
- sreg <= sreg + rx2;
- sreg <= sreg ror 1;
- else then
- sreg <= sreg;
- end if;
- end process;
- // styrenhet
- process(clk) begin
- if rising_edge(clk) then
- if rst = '1' then
- bit_counter <= "0000000000";
- state_counter <= "0000";
- run <= '0';
- lp <= '0';
- sp <= '0';
- elsif run = '1' then
- sp <= '0';
- lp <= '0';
- bit_counter <= bit_counter + '1';
- if bit_counter = "110110010" and state_counter = '0' then -- Läs första biten
- sp <= '1';
- bit_counter <= "0000000000";
- state_counter <= state_counter + '1';
- elsif bit_counter = "1101100100" then // Läs nästa bit
- sp <= '1';
- bit_counter <= "0000000000";
- state_counter <= state_counter + '1';
- elsif bit_counter = "110110010" and state_counter = "1001" then
- lp <= '1';
- bit_counter <= "0000000000";
- state_counter <= "0000";
- else then
- bit_counter <= bit_counter;
- end if;
- elsif rx1 = '0' and rx2 = '1' then
- run <= '1';
- bit_counter <= bit_counter + 1;
- else then
- run <= run;
- end if;
- end if;
- end process;
- // 2-bitsräknare
- process(clk) begin
- if rising_edge(clk) then
- if rst = '1' then
- pos <= "00";
- elsif pos = "11" then
- pos <= "00";
- elsif lp = '1' then
- pos <= pos + 1;
- else then
- pos <= pos;
- end if;
- end if;
- end process;
- // 16- bitsregister
- process(clk) begin
- if rising_edge(clk) then
- if rst = '1' then
- pos0 <= "0000";
- pos1 <= "0000";
- pos2 <= "0000";
- pos3 <= "0000";
- elsif pos = "00" then
- pos0 <= nya_talet;
- elsif pos = "01" then
- pos1 <= nya_talet;
- elsif pos = "10" then
- pos2 <= nya_talet;
- elsif pos = "11" then
- pos3 <= nya_talet;
- else then
- pos0 <= pos0;
- end if;
- end if;
- end process;
- -- *****************************
- -- * Multiplexad display *
- -- *****************************
- -- Inkoppling av komponenten leddriver
- led: leddriver port map (clk, rst, seg, an, tal);
- end Behavioral;
Add Comment
Please, Sign In to add comment