Hello,
I start playing with a Spartan 3 demo board. I want to program a 8 bits counter with one button that increments the counter, one button that decrements the counter and one reset button that erases the counter. Output of the counter is connected to the 8 leds.
Here is the very naive code:
library IEEE; use IEEE.STD_LOGIC_1164.ALL; use IEEE.STD_LOGIC_ARITH.ALL; use IEEE.STD_LOGIC_UNSIGNED.ALL;
---- Uncomment the following library declaration if instantiating
---- any Xilinx primitives in this code.
--library UNISIM;
--use UNISIM.VComponents.all;
entity test is port ( inc: in std_logic; dec: in std_logic; reset: in std_logic; led_value: out std_logic_vector(7 downto 0) ); end test;
architecture Behavioral of test is begin process (inc, dec, reset) variable counter_value: std_logic_vector(7 downto 0); variable flag_inc: std_logic; variable flag_dec: std_logic; begin if (reset='1') then counter_value := "00000000"; flag_inc := '0'; flag_dec := '0'; end if;
if (inc='1' and flag_inc='0') then flag_inc := '1'; counter_value := counter_value + 1; end if;
if (dec='1' and flag_dec='0') then flag_dec := '1'; counter_value := counter_value - 1; end if; if (inc='0') then flag_inc := '0'; end if; if (dec='0') then flag_dec := '0'; end if;
led_value