一首永无止境的歌伴你一起欣赏花样LED--FPGA。
顶层实体:
这是原理图形式:
将下面个程序生成原理图模块,这样方便调用!上面的视频已经演示了!
分频程序:
LIBRARY IEEE;
USE IEEE.STD_LOGIC_1164.ALL;
USE IEEE.STD_LOGIC_UNSIGNED.ALL;
entity fp50M is
port(clk_50MHZ: in std_logic;
clk_1HZ: out std_logic
);
end fp50M;
architecture behav of fp50M is
signal clk_1HZ_r: std_logic;
signal count : std_logic_vector(23 downto 0);
begin
process (clk_50MHZ)
begin
if clk_50MHZ'event and clk_50MHZ='1' then
if count="101111101011110000100000"then
count<=(others=>'0');
clk_1HZ_r<=not clk_1HZ_r;
else count<=count+1;
clk_1HZ<=clk_1HZ_r;
end if;
end if;
end process;
end behav;
下面是各种LED控制程序(提供三个):
LED闪烁:
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all ;
entity led_shan is
port (clk,reset: in std_logic;
led : out std_logic_vector(10 downto 0)
);
end led_shan;
architecture behva of led_shan is
signal led_r: std_logic;
begin
process(clk)
begin
if reset='0' then
led<="11111111111";
else
if clk'event and clk='1' then
led_r<=not led_r;
if led_r='0'then
led<="00000000000";
else
if led_r='1' then
led<="11111111111";
end if;
end if;
--case led_r is
--when '0' => led<="00000000000";
--when '1' =>led<="11111111111";
--end case;
end if;
end if;
end process;
end ;
LED跑马灯:
library ieee ;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
entity led_liu is
port (clk ,reset: in std_logic;
led : out std_logic_vector(10 downto 0)
);
end led_liu;
architecture behav of led_liu is
signal bcd_r :std_logic_vector(3 downto 0);
begin
process(clk,reset)
begin
if reset='0'then
led<="11111111111";
else
if clk'event and clk='1' then
bcd_r<=bcd_r+1;
case bcd_r is
when "0000"=>led<="11111011111";
when "0001"=>led<="11110101111";
when "0010"=>led<="11101110111";
when "0011"=>led<="11011111011";
when "0100"=>led<="10111111101";
when "0101"=>led<="01111111110";
when "0110"=>led<="10111111101";
when "0111"=>led<="11011111011";
when "1000"=>led<="11101110111";
when "1001"=>led<="11110101111";
when "1010"=>led<="11111011111" ; bcd_r<="0000";
when others=>led<="11111111111";
end case;
end if;
end if;
end process;
end;
LED流水:
LIBRARY IEEE ;
USE IEEE.STD_LOGIC_1164.all ;
use ieee.std_logic_unsigned.all;
entity liu is
port(clk ,reset : in std_logic;
led : out std_logic_vector(10 downto 0)
);
end liu;
architecture behave of liu is
signal bcd_r :std_logic_vector(3 downto 0);
begin
process(clk,reset)
begin
if reset='0'then
led<="11111111111";
else
if clk'event and clk='1' then
bcd_r<=bcd_r+1;
case bcd_r is
when "0000"=>led<="11111111110";
when "0001"=>led<="11111111100";
when "0010"=>led<="11111111000";
when "0011"=>led<="11111110000";
when "0100"=>led<="11111100000";
when "0101"=>led<="11111000000";
when "0110"=>led<="11110000000";
when "0111"=>led<="11100000000";
when "1000"=>led<="11000000000";
when "1001"=>led<="10000000000";
when "1010"=>led<="00000000000" ; bcd_r<="0000";
when others=>null;
end case;
end if;
end if;
end process;
end
LED闪烁、跑马、流水,等各种花样LED的.SOF文件:http://share.eepw.com.cn/share/download/id/79219