{:soso_e100:}{:soso_e100:}{:soso_e100:}{:soso_e100:}{:soso_e100:}{:soso_e100:}{:soso_e100:}{:soso_e100:}{:soso_e100:}{:soso_e100:}{:soso_e100:}{:soso_e100:}{:soso_e100:}{:soso_e100:}{:soso_e100:}{:soso_e100:}{:soso_e100:}{:soso_e100:}{:soso_e100:}{:soso_e100:}{:soso_e100:}{:soso_e100:}{:soso_e100:}{:soso_e100:}{:soso_e100:}{:soso_e100:}{:soso_e100:}{:soso_e100:}{:soso_e100:}{:soso_e100:}{:soso_e100:}{:soso_e100:}这个程序是实现四位数码显示灯亮的选择及数据的加减,不过我能力有限,还请大家帮我看看,优化一下在下感激不尽!!
{:soso_e100:}{:soso_e100:}{:soso_e100:}{:soso_e100:}{:soso_e100:}{:soso_e100:}{:soso_e100:}{:soso_e100:}{:soso_e100:}{:soso_e100:}{:soso_e100:}{:soso_e100:}{:soso_e100:}{:soso_e100:}{:soso_e100:}{:soso_e100:}{:soso_e100:}{:soso_e100:}{:soso_e100:}{:soso_e100:}{:soso_e100:}{:soso_e100:}{:soso_e100:}{:soso_e100:}{:soso_e100:}{:soso_e100:}{:soso_e100:}{:soso_e100:}{:soso_e100:}{:soso_e100:}{:soso_e100:}{:soso_e100:}
----------------------------------------------------------------------------------
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 using
-- arithmetic functions with Signed or Unsigned values
--use IEEE.NUMERIC_STD.ALL;
-- Uncomment the following library declaration if instantiating
-- any Xilinx primitives in this code.
--library UNISIM;
--use UNISIM.VComponents.all;
entity shuma is
port (clk: in std_logic;
btn : in std_logic_vector(4 downto 0);
sel : out std_logic_vector(3 downto 0);
led : out std_logic_vector(7 downto 0)
--doutU,doutD, doutL,doutR : out std_logic
);
end shuma;
architecture Behavioral of shuma is
signal count: std_logic_vector(50 downto 0);
signal num1,num2,num3,num4,code :integer range -10 to 10;
--signal btnUB,btnDB,btnLB:std_logic;
signal dout: std_logic;
signal btn_num :integer range 1 to 4;
begin
process(clk)
begin
if (clk'event and clk='1') then
count<=count+1;
end if;
end process;
process(count(16),btn)
variable temp:integer range 0 to 110;
begin
if count(16)'event and count(16)='1' then
temp:=temp+1;
if(btn="00000") then --键未按下不开始计数,计数一直归零
temp:=0;
end if;
if temp>100 then --延迟100个周期再判断
dout<='1';
else
dout<='0';
end if;
end if;
end process;
process(dout)
begin
if dout'event and dout='1' then
case btn is
when"00100"=>num1<=num1+1;
if num1>=9 then
num1<=0;
end if;
when"00010"=>num1<=num1-1;
if num1<=0 then
num1<=9;
end if;
when others=>
end case;
end if;
end process;
process(dout)
begin
if dout'event and dout='1' then
case btn is
when "00001" => btn_num <= btn_num+1;
when "01000" => btn_num <= btn_num-1;
when others=>
end case;
end if;
end process;
process(btn_num)
begin
case btn_num is
when 1=>sel<="1110";
when 2=>sel<="1101";
when 3=>sel<="1011";
when 4=>sel<="0111";
when others=>
end case;
end process;
process(count)
begin
if (count(25)'event and count(25)='1') then
code<=code+1;
end if;
end process;
process( num1)
begin
case num1 is
when 0 => led <="11000000"; --0
when 1 => led <="11111001"; --1
when 2 => led <="10100100"; --2
when 3 => led <="10110000"; --3
when 4 => led <="10011001"; --4
when 5 => led <="10010010"; --5
when 6 => led <="10000010"; --6
when 7 => led <="11111000"; --7
when 8 => led <="10000000"; --8
when 9 => led <="10010000"; --9
when others =>
end case;
end process;
end Behavioral;