summaryrefslogtreecommitdiffstats
path: root/lab3/leddriver.vhd
diff options
context:
space:
mode:
authorGustav Sörnäs <gustav@sornas.net>2022-02-14 17:18:38 +0100
committerGustav Sörnäs <gustav@sornas.net>2022-02-14 17:18:38 +0100
commit82197955991947fe0872712460bb988b6c2d0ef9 (patch)
tree3c91727a7ac088b197290fbf8486aba77ce8a9cf /lab3/leddriver.vhd
parent1ba036ef511af46a19fe81823b6e66bb4e98c45c (diff)
downloadtsea83-82197955991947fe0872712460bb988b6c2d0ef9.tar.gz
add rest of lab3
Diffstat (limited to 'lab3/leddriver.vhd')
-rwxr-xr-xlab3/leddriver.vhd60
1 files changed, 60 insertions, 0 deletions
diff --git a/lab3/leddriver.vhd b/lab3/leddriver.vhd
new file mode 100755
index 0000000..f45a15c
--- /dev/null
+++ b/lab3/leddriver.vhd
@@ -0,0 +1,60 @@
+library IEEE;
+use IEEE.STD_LOGIC_1164.ALL;
+use IEEE.NUMERIC_STD.all;
+
+entity leddriver is
+ 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 leddriver;
+
+architecture Behavioral of leddriver is
+ signal segments : UNSIGNED (6 downto 0);
+ signal counter_r : UNSIGNED(17 downto 0) := "000000000000000000";
+ signal v : UNSIGNED (3 downto 0);
+ signal dp : STD_LOGIC;
+begin
+ -- decimal point not used
+ dp <= '1';
+ seg <= (dp & segments);
+
+ with counter_r(17 downto 16) select
+ v <= value(15 downto 12) when "00",
+ value(11 downto 8) when "01",
+ value(7 downto 4) when "10",
+ value(3 downto 0) when others;
+
+ process(clk) begin
+ if rising_edge(clk) then
+ counter_r <= counter_r + 1;
+ case v is
+ when "0000" => segments <= "0000001";
+ when "0001" => segments <= "1001111";
+ when "0010" => segments <= "0010010";
+ when "0011" => segments <= "0000110";
+ when "0100" => segments <= "1001100";
+ when "0101" => segments <= "0100100";
+ when "0110" => segments <= "0100000";
+ when "0111" => segments <= "0001111";
+ when "1000" => segments <= "0000000";
+ when "1001" => segments <= "0000100";
+ when "1010" => segments <= "0001000";
+ when "1011" => segments <= "1100000";
+ when "1100" => segments <= "0110001";
+ when "1101" => segments <= "1000010";
+ when "1110" => segments <= "0110000";
+ when others => segments <= "0111000";
+ end case;
+
+ case counter_r(17 downto 16) is
+ when "00" => an <= "0111";
+ when "01" => an <= "1011";
+ when "10" => an <= "1101";
+ when others => an <= "1110";
+ end case;
+ end if;
+ end process;
+
+end Behavioral;
+