FPGA实验报告 - 图文 联系客服

发布时间 : 星期一 文章FPGA实验报告 - 图文更新完毕开始阅读

实验二、跑马灯设计

一、实验目的

1. 学习状态机的设计技巧; 2. 掌握CASE 语句的使用。

二、实验器材

1. KH-310 下载板; 2. KH-310 时钟模块;

3. KH-310 LED 显示模块。

三、文件档名

加载:led.sof 烧录:led.pof

项目工程文件:led.qpf

四、实验内容

控制8 个LED 进行花式显示,设计四种显示模式: 1. 从左到右逐个点亮LED; 2. 从右到左逐个点亮LED; 3. 从两边到中间逐个点亮LED; 4. 从中间到两边逐个点亮LED。

四种模式循环切换,由复位键rst 控制系统的运行与停止。

五、实验原理

图3.23

可用移位寄存器来控制逐个点亮LED 的操作,移位的频率为1Hz。

六、实验连线

输入信号:

时钟clk 接10Hz 输入(SW7) P152;

复位rst 接拨动开关I01(拨码开关SW3 左1)P1 ; 输出信号:

8 位输出信号接LED 模块O25—O32。P43~P50;

七、实验操作

下载程序,将SW7 拨至第二段(10Hz),拨码开关SW3 的IO1 拨至ON 的位置,此时,LED 灯的前8 位会有规律的闪烁。

八、实验程序

1. VHDL 程序

library ieee;

use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity led is

port(clk:in std_logic; rst:in std_logic;

q :out std_logic_vector(7 downto 0)); end;

architecture led of led is

constant s0:std_logic_vector(1 downto 0):=\模式1 constant s1:std_logic_vector(1 downto 0):=\―模式2 constant s2:std_logic_vector(1 downto 0):=\―模式3 constant s3:std_logic_vector(1 downto 0):=\―模式4

signal present:std_logic_vector(1 downto 0); -- ――当前模式 signal q1:std_logic_vector(7 downto 0); signal count:std_logic_vector(3 downto 0); begin

process(rst,clk) begin

if(rst='0')then -- ――系统初始化 present<=s0;

q1<=(others=>'0');

elsif(clk'event and clk='1')then case present is

when s0 => if(q1=\――S0模式:从左到右逐个点亮LED

q1<=\

else if(count=\

count<=(others=>'0'); q1<=\ present<=s1;

else q1<=q1(0) & q1(7 downto 1); count<=count+1; present<=s0; end if; end if;

when s1 => if(count=\模式:从右到左逐个点亮LED count<=(others=>'0'); q1<=\ present<=s2;

else q1<=q1(6 downto 0) & q1(7); count<=count+1; present<=s1; end if;

when s2 => if(count=\模式:从两边到中间逐个点亮LED count<=(others=>'0'); q1<=\ present<=s3;

else q1(7 downto 4)<=q1(4) & q1(7 downto 5); q1(3 downto 0)<=q1(2 downto 0) & q1(3); count<=count+1; present<=s2; end if;

when s3 => if(count=\模式:从中间到两边逐个点亮LED count<=(others=>'0'); q1<=\ present<=s0;

else q1(7 downto 4)<=q1(6 downto 4) & q1(7); q1(3 downto 0)<=q1(0) & q1(3 downto 1); count<=count+1; present<=s3; end if; end case; end if;

end process; q<=q1; end;