------------------------------------------------------------------------ -- hw3a.vhd -- Demonstrate basic functions ------------------------------------------------------------------------ -- Author: Don Bouldin, Univ. of Tennessee, 9/19/05 ------------------------------------------------------------------------ -- This module tests basic functions and I/O on the Spartan3 board. ------------------------------------------------------------------------ library IEEE; use IEEE.STD_LOGIC_1164.ALL; use IEEE.STD_LOGIC_ARITH.ALL; use IEEE.STD_LOGIC_UNSIGNED.ALL; entity hw3a is Port ( clock_50MHz : in std_logic; btn0: in std_logic; swt : in std_logic_vector(7 downto 0); -- swt(7) = most significant sliding switch; OFF = LOW; ON = HIGH -- swt(0) = least significant sliding switch; OFF = LOW; ON = HIGH led : out std_logic_vector(7 downto 0); -- led(7) = most significant led is ON when active HIGH -- led(0) = least significant led is ON when active HIGH seg : out std_logic_vector(7 downto 0); -- segment lights when active LOW -- seg(0) = seg-a -- seg(1) = seg-b -- seg(2) = seg-c -- seg(3) = seg-d -- seg(4) = seg-e -- seg(5) = seg-f -- seg(6) = seg-g -- seg(7) = dp dig : out std_logic_vector(3 downto 0) -- dig(3) = most significant digit is displayed when active LOW -- dig(0) = least significant digit is displayed when active LOW ); end hw3a; architecture Behavioral of hw3a is SIGNAL reset_pb_flag, pb_flag, clock_10hz: std_logic; SIGNAL initialize : STD_LOGIC; SIGNAL seg_3 : std_logic_vector(7 downto 0); SIGNAL seg_2 : std_logic_vector(7 downto 0); SIGNAL seg_1 : std_logic_vector(7 downto 0); SIGNAL seg_0 : std_logic_vector(7 downto 0); COMPONENT hierarch PORT( clock_50Mhz, btn0, reset_pb_flag: IN STD_LOGIC; pb_flag, clock_10Hz : OUT STD_LOGIC ); END COMPONENT; -- Use Port Map to connect signals between components in the hiearchy BEGIN hw3a : hierarch PORT MAP (clock_50Mhz => clock_50Mhz, btn0 => btn0, reset_pb_flag => reset_pb_flag, pb_flag => pb_flag, clock_10hz => clock_10hz ); -- begin loop PROCESS BEGIN -- initialize will be initialized to '0' at power up IF initialize = '0' THEN -- This code resets the critical signals once at power up led(7 downto 0) <= "00000000"; seg_3(7 downto 0) <= "11111111"; seg_2(7 downto 0) <= "11111111"; seg_1(7 downto 0) <= "11111111"; seg_0(7 downto 0) <= "11111111"; WAIT UNTIL clock_10hz'EVENT and clock_10hz = '1'; --reset push button flag after wait reset_pb_flag <= '0'; ELSE initialize <= '1'; WAIT UNTIL clock_10hz'EVENT and clock_10hz = '1'; --reset push button flag after wait reset_pb_flag <= '0'; -- display each of the four digits for 0.1 second each forever seg(7 downto 0) <= seg_0(7 downto 0) ; dig <= "1110" ; --digit(0) is ON --now wait for 0.1 second WAIT UNTIL clock_10hz'EVENT and clock_10hz = '1'; seg(7 downto 0) <= seg_1(7 downto 0) ; dig(3 downto 0) <= "1101" ; --digit(1) is ON --now wait for 0.1 second WAIT UNTIL clock_10hz'EVENT and clock_10hz = '1'; seg(7 downto 0) <= seg_2(7 downto 0); dig(3 downto 0) <= "1011" ; --digit(2) is ON --now wait for 0.1 second WAIT UNTIL clock_10hz'EVENT and clock_10hz = '1'; seg(7 downto 0) <= seg_3(7 downto 0); dig(3 downto 0) <= "0111" ; --digit(3) is ON -- repeat display until USER sets sliding switches and then presses btn0 -- if btn0_pressed has NOT occurred then skip to repeat this loop, -- else copy the switch settings and update the display IF pb_flag = '1' THEN -- copy the sliding switch settings to the leds led(7 downto 0) <= swt(7 downto 0); -- copy the sliding switch settings to the internal digit segments seg_3(7 downto 0) <= not (swt(7 downto 0)) ; seg_2(7 downto 0) <= not (swt(7 downto 0)) ; seg_1(7 downto 0) <= not (swt(7 downto 0)) ; seg_0(7 downto 0) <= not (swt(7 downto 0)) ; reset_pb_flag <= '1'; ELSE END IF; END IF; -- repeat loop END PROCESS; END Behavioral;