三、仿真波形及波形分析:
点阵显示采用行扫描模式
四、源程序:
---------------------------------------- --File Name :ShaLou.vhd --System :Quartus II 9.1
--Author :Wang Hongjie 2012210176 --Revision :Version 1.0,2014-11-3 ---------------------------------------- library ieee;
use ieee.std_logic_1164.all; entity shalou is port(
clk:in std_logic; --系统时钟
sw:in std_logic; --拨码开关SW1控制沙粒移动方向 bto:in std_logic; --启动 暂停 bt1:in std_logic; --复位 bt2:in std_logic; --速度 lieh:out std_logic_vector(7 downto 0); --RED liel:out std_logic_vector(7 downto 0); --GREEN hang:out std_logic_vector(7 downto 0); --行扫描 a:out std_logic_vector(6 downto 0); --七段数码管 cat:out std_logic_vector(5 downto 0)); --数码管选择 end entity;
Architecture a of shalou is
signal temp:integer range 0 to 49999; signal clktmp:std_logic; signal clkout : std_logic;
signal temp1:integer range 0 to 199; signal clktmp1:std_logic; signal clkout1 : std_logic;
signal temp2:integer range 0 to 299; signal clktmp2:std_logic; signal clkout2 : std_logic;
signal qt: integer range 0 to 5; signal bto_tmp: std_logic; signal bto_out: std_logic;
signal qt1: integer range 0 to 5; signal bto_tmp1: std_logic; signal bto_out1: std_logic; signal qt2: integer range 0 to 5; signal bto_tmp2: std_logic;
signal sudu:integer range 0 to 2;
signal sudu_t:integer range 0 to 299;
signal q:integer range 0 to 60; signal p:integer range 0 to 16; signal ge:integer range 0 to 9; signal shi:integer range 0 to 9;
signal dz_kongzhi:integer range 0 to 7; signal cat_kongzhi:integer range 0 to 1; begin
p1:process(clk) --时钟 begin
if clk'event and clk='1' then if temp=49999 then
temp<=0;clktmp<=not clktmp; else
temp<=temp+1; end if; end if;
end process p1; clkout<=clktmp;
p2:process(clkout) --分频 begin if clkout'event and clkout='0' then if temp1=199 then temp1<=0; clktmp1<= not clktmp1; else temp1<=temp1+1; end if; end if; end process p2; clkout1<=clktmp1; p3:process(clkout1) begin if clkout'event and clkout='0' then
if cat_kongzhi=0 then cat_kongzhi<=1; else cat_kongzhi<=0; end if;
if dz_kongzhi=7 then dz_kongzhi<=0; else dz_kongzhi<=dz_kongzhi+1; end if; end if; end process p3;
p4:process(clkout,qt,bto,qt1,bt1,qt2,bt2) begin
if clkout'event and clkout='0' then if bto='1' then if qt=5 then else
qt<=qt+1; end if;
if qt=4 then
bto_tmp<='1'; else
bto_tmp<='0'; end if; else
qt<=0; end if; end if;
if clkout'event and clkout='0' then if bt1='1' then if qt1=5 then else
qt1<=qt1+1; end if;
if qt1=4 then
bto_tmp1<='1'; else
bto_tmp1<='0'; end if; else
qt1<=0; end if; end if;
if clkout'event and clkout='0' then if bt2='1' then if qt2=5 then else
qt2<=qt2+1; end if;
if qt2=4 then
bto_tmp2<='1'; else
bto_tmp2<='0'; end if;
else
qt2<=0; end if; end if; end process;
p5:process(bto_tmp,bto_tmp1) begin
if(bto_tmp'event and bto_tmp='1')then bto_out<=not bto_out; else
bto_out<=bto_out; end if;
if(bto_tmp1'event and bto_tmp1='1')then bto_out1<=not bto_out1; else
bto_out1<=bto_out1; end if;
if(bto_tmp2'event and bto_tmp2='1')then if(sudu=2) then sudu<=0; else sudu<=sudu+1; end if; end if; end process;
p6:process(sudu) begin
case sudu is
when 0 =>sudu_t<=199; when 1 =>sudu_t<=99; when 2 =>sudu_t<=299; end case; end process;
p7:process(clkout,sudu_t) begin if clkout'event and clkout='0' then if temp2=sudu_t then temp2<=0; clktmp2<= not clktmp2; else temp2<=temp2+1; end if; end if;
--fen pin