每个开发板的LED就仿佛“Hello World”一样,可以方便快速的了解初步开发流程,在学习了官方的教程后,我也奉上我的LED,哈哈,看~
程序是用VHDL编写的:
--库声明
LIBRARY IEEE;
USE IEEE.STD_LOGIC_1164.ALL;
USE IEEE.STD_LOGIC_ARITH.ALL;
USE IEEE.STD_LOGIC_UNSIGNED.ALL;
--实体
ENTITY led_run IS
PORT(
SYS_CLK : IN STD_LOGIC;--时钟输入
SYS_RSTN : IN STD_LOGIC;--复位输入
LED_OUT : OUT STD_LOGIC_VECTOR(3 downto 0)--LED输出
);
END ENTITY led_run;
--结构体
ARCHITECTURE behav OF led_run IS
--信号声明
signal led_out_i : std_logic_vector(3 downto 0):= (others=>'0');
signal clk_cnt : std_logic_vector(24 downto 0):= (others=>'0');
signal led_cnt : std_logic_vector(2 downto 0) := (others=>'0');
BEGIN
LED_OUT <= led_out_i;
--对50MHz时钟计数,并控制led_cnt计数器
clk_cnt_proc : process(SYS_RSTN,SYS_CLK)
begin
if SYS_RSTN = '0' then
clk_cnt <= (others => '0');
led_cnt <= (others => '0');
elsif rising_edge(SYS_CLK) then
--50MHz下延时0.5s
if clk_cnt = conv_std_logic_vector(24999999,25) then
clk_cnt <= conv_std_logic_vector(0,25);
led_cnt <= led_cnt + '1';
else
clk_cnt <= clk_cnt + '1';
led_cnt <= led_cnt;
end if;
end if;
end process clk_cnt_proc;
--根据led_cnt的值,输出相应LED状态
led_flicker_proc : process(SYS_RSTN,SYS_CLK)
begin
if SYS_RSTN = '0' then
led_out_i <= "1111";
elsif rising_edge(SYS_CLK) then
case(led_cnt) is
when "000" => led_out_i <= "0111";
when "001" => led_out_i <= "1011";
when "010" => led_out_i <= "1101";
when "011" => led_out_i <= "1110";
when "100" => led_out_i <= "1101";
when "101" => led_out_i <= "1011";
when "110" => led_out_i <= "0111";
when "111" => led_out_i <= "1111";
end case;
end if;
end process led_flicker_proc;
END ARCHITECTURE behav;