名称:基于FPGA的多路彩灯控制器VHDL代码Quartus仿真(文末获取)
软件:Quartus
语言:VHDL
代码功能:
多路彩灯控制器
综合训练内容要求
设计一台基于FPGA的多路彩灯控制器的设计。要求如下
1.彩灯从左到右逐次闪亮。然后从右到左逐次熄灭
2.彩灯两边同时亮两个,然后逐次向中间点亮
3.彩灯从左到右两个两个点亮,然后从右到左两个两个逐次点亮
4.彩灯中间两个点亮,然后同时向两边散开
5.设置节拍选择按钮,控制彩灯变化节奏
1. 工程文件
2. 程序文件
原理图
代码
3. 程序编译
4. RTL图
5. 仿真图
整体仿真图
模式1,先从左到右,再从右到左
模式2,两边同时亮2个,然后逐次向中间点亮
模式3,从左到右拉高点亮,再从右到左两个点亮
模式4,中间2个点亮,再向两边散开
分频模块
控制模块
部分代码展示:
LIBRARY ieee; USE ieee.std_logic_1164.all; USE ieee.std_logic_unsigned.all; --彩灯控制模块 ENTITY caideng_ctrl IS PORT ( clk_div : IN STD_LOGIC;--控制时钟 reset_p : IN STD_LOGIC;--高电平复位 led : OUT STD_LOGIC_VECTOR(7 DOWNTO 0)--输出灯 ); END caideng_ctrl; ARCHITECTURE ctrl OF caideng_ctrl IS --中间信号 SIGNAL led_buf : STD_LOGIC_VECTOR(7 DOWNTO 0) := "00000000"; SIGNAL state_count : STD_LOGIC_VECTOR(7 DOWNTO 0) := "00000000";--状态计数器 BEGIN PROCESS (clk_div, reset_p) BEGIN IF (reset_p = '1') THEN--复位清零 state_count <= "00000000"; ELSIF (clk_div'EVENT AND clk_div = '1') THEN IF (state_count = "00100101") THEN state_count <= "00000000";--运行结束后循环 ELSE state_count <= state_count + "00000001";--计数 END IF; END IF; END PROCESS; led<=led_buf; PROCESS (clk_div, reset_p) BEGIN IF (reset_p = '1') THEN--复位清零 led_buf <= "00000000"; ELSIF (clk_div'EVENT AND clk_div = '1') THEN CASE state_count IS --模式1,先从左到右,再从右到左 WHEN "00000000" => led_buf <= "10000000"; WHEN "00000001" => led_buf <= "11000000"; WHEN "00000010" => led_buf <= "11100000"; WHEN "00000011" => led_buf <= "11110000"; WHEN "00000100" => led_buf <= "11111000"; WHEN "00000101" => led_buf <= "11111100"; WHEN "00000110" => led_buf <= "11111110"; WHEN "00000111" => led_buf <= "11111111"; WHEN "00001000" => led_buf <= "11111110"; WHEN "00001001" => led_buf <= "11111100"; WHEN "00001010" => led_buf <= "11111000"; WHEN "00001011" => led_buf <= "11110000"; WHEN "00001100" => led_buf <= "11100000"; WHEN "00001101" => led_buf <= "11000000"; WHEN "00001110" => led_buf <= "10000000"; WHEN "00001111" => led_buf <= "00000000"; --模式2,两边同时亮2个,然后逐次向中间点亮 WHEN "00010000" => led_buf <= "10000001"; WHEN "00010001" => led_buf <= "11000011"; WHEN "00010010" => led_buf <= "11100111"; WHEN "00010011" => led_buf <= "11111111"; --模式3,从左到右拉高点亮,再从右到左两个点亮 WHEN "00010100" => led_buf <= "11000000"; WHEN "00010101" => led_buf <= "01100000"; WHEN "00010110" => led_buf <= "00110000"; WHEN "00010111" => led_buf <= "00011000"; WHEN "00011000" => led_buf <= "00001100"; WHEN "00011001" => led_buf <= "00000110";
源代码
扫描文章末尾的公众号二维码