赞
踩
名称:多路彩灯控制器VHDL代码Quartus仿真(文末获取)
软件:Quartus
语言:VHDL
代码功能:
多路彩灯控制器
一。综合训练内容要求
设计一台基于FPGA的多路彩灯控制器的设计,要求如下
1.彩灯从左到右逐次闪亮,然后从右到左逐次熄灭
2.彩灯两边同时亮两个,然后逐次向中间点亮
3.彩灯从左到右两个两个点亮,然后从右到左两个两个逐次点亮。
4.彩灯中间两个点亮,然后同时向两边散开
1. 工程文件
2. 程序文件
原理图
代码
3. 程序编译
4. RTL图
5. 仿真图
整体仿真图
花样1,从左到右亮,再从右到左灭
花样2,两边向中间点亮
花样3,从左到右两个两个点亮,再从右到左点亮
花样4,中间两个点亮,再向两边散开
分频模块仿真图
控制模块仿真图
部分代码展示:
LIBRARY ieee; USE ieee.std_logic_1164.all; USE ieee.std_logic_unsigned.all; --彩灯控制模块 ENTITY control IS PORT ( clk_1 : IN STD_LOGIC;--输出时钟1,对应变化节奏1 clk_2:IN STD_LOGIC;--输出时钟2,对应变化节奏2 button:IN STD_LOGIC;--节拍选择按键,通过切换clk_1和clk_2控制节奏 rst : IN STD_LOGIC;--高电平复位 led : OUT STD_LOGIC_VECTOR(7 DOWNTO 0)--输出彩灯 ); END control; ARCHITECTURE behave OF control IS --中间信号 SIGNAL clk : STD_LOGIC; SIGNAL cnt : integer := 0;--计数器 BEGIN clk<=clk_1 when (button='1') else clk_2;----节拍选择按键,通过切换clk_1和clk_2控制节奏 PROCESS (clk, rst) BEGIN IF (rst = '1') THEN--复位清零 cnt <= 0; ELSIF (clk'EVENT AND clk = '1') THEN IF (cnt = 35) THEN cnt <= 0;--运行结束后循环 ELSE cnt <= cnt + 1;--计数 END IF; END IF; END PROCESS; PROCESS (clk, rst) BEGIN IF (rst = '1') THEN--复位清零 led <= "00000000"; ELSIF (clk'EVENT AND clk = '1') THEN CASE cnt IS --花样1,从左到右亮,再从右到左灭 WHEN 0 =>led <= "10000000"; WHEN 1 =>led <= "11000000"; WHEN 2 =>led <= "11100000"; WHEN 3 =>led <= "11110000"; WHEN 4 =>led <= "11111000"; WHEN 5 =>led <= "11111100"; WHEN 6 =>led <= "11111110"; WHEN 7 =>led <= "11111111"; WHEN 8 =>led <= "11111110"; WHEN 9 =>led <= "11111100"; WHEN 10 =>led <= "11111000"; WHEN 11 =>led <= "11110000"; WHEN 12 =>led <= "11100000"; WHEN 13 =>led <= "11000000"; WHEN 14 =>led <= "10000000"; --花样2,两边向中间点亮 WHEN 15 =>led <= "10000001"; WHEN 16 =>led <= "11000011"; WHEN 17 =>led <= "11100111"; WHEN 18 =>led <= "11111111"; --花样3,从左到右两个两个点亮,再从右到左点亮 WHEN 19 =>led <= "11000000"; WHEN 20 =>led <= "01100000"; WHEN 21 =>led <= "00110000"; WHEN 22 =>led <= "00011000"; WHEN 23 =>led <= "00001100"; WHEN 24 =>led <= "00000110"; WHEN 25 =>led <= "00000011"; WHEN 26 =>led <= "00000110"; WHEN 27 =>led <= "00001100"; WHEN 28 =>led <= "00011000"; WHEN 29 =>led <= "00110000"; WHEN 30 =>led <= "01100000"; WHEN 31 =>led <= "11000000"; --花样4,中间两个点亮,再向两边散开
扫描文章末尾的公众号二维码
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。