VHDL+LED控制器+50MHZ分频+例化

3 篇文章 0 订阅
2 篇文章 0 订阅

题目:设计一个LED控制器,能够控制LED以不同速度闪烁,具体要求如下:
要求:开关SW1做为多路输入端,当开关为高电平‘1’时,LED以1秒间隔闪烁(亮0.5秒,灭0.5秒循环往复)。当开关为低电平‘0’时,LED以10秒间隔闪烁(亮5秒,灭5秒循环往复)。

在这里插入图片描述


思路

先分别写出分频器,计数器,选择器,然后例化3个器件

提示:以下是本篇文章正文内容,下面案例可供参考

一、必要器件

1.分频器

代码如下(示例):

library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
entity fenpin is
	port (clk50m:in std_logic;
			clk:out std_logic);
end entity;

architecture fen of fenpin is
signal cnt: integer range 0 to 24999999; 
signal clkout :std_logic;
begin
	process(clk50m)
	begin
	if clk50m'event and clk50m = '1' then
		if cnt = 24999999 then
			cnt <= 0;
			clkout <= not clkout;
		else
			cnt <= cnt + 1;
	end if;
	end if;
	end process;
	clk <= clkout;
end architecture;

2.计数器

代码如下(示例):

library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
entity count is
port(clk1,rst:in std_logic;
		clk10: out std_logic);
end count;
architecture count10 of count is
signal cnt:integer range 0 to 4; 
signal clkout :std_logic;
begin
	process(clk1)
	begin 
	if rst='1' then 
		cnt<=0;
	elsif rising_edge(clk1) then
		if cnt = 4 then
			cnt<= 0;
			clkout <= not clkout;
		else 
			cnt<=cnt+1;
		end if;
	end if;
	end process;
	clk10<=clkout;
end count10;


3.选择器

代码如下(示例):

library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
entity mux is
port (sw :in std_logic;
		clk1:in std_logic;
		clk10:in std_logic;
		clkout:out std_logic);
end mux;
architecture mux21 of mux is
begin
	process(sw ,clk1,clk10)
	begin
	if sw='1' then 
		clkout<= clk1;
	else
		clkout<= clk10;
	end if;
	end process;
end mux21;

二、元件例化设计顶层

代码如下(示例):

library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
entity leds is
port(clki,SW:in std_logic;
		clko:out std_logic);
end leds;
architecture led of leds is
signal u1,u2:std_logic;
component fenpin is
	port (clk50m:in std_logic;
			clk:out std_logic);
end component;
component count is
	port(clk1,rst:in std_logic;
		clk10: out std_logic);
end component;
component mux is
	port (sw :in std_logic;
			clk1:in std_logic;
			clk10:in std_logic;
			clkout:out std_logic);
end component;
begin
	fen:fenpin port map(clki,u1);
	cnt:count port map(u1,'0',u2);
	m:mux port map(SW,u1,u2,clko);
end led;
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值