--8*8点阵扫描控制模块--汉字滚动显示
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;
entity led_88 is
port
(
clkin,resetin:in std_logic;--时钟,复位信号输入
line:out std_logic_vector(7 downto 0);--点阵列
row:out std_logic_vector(7 downto 0);--点阵行
--
led_out:out std_logic--指示流动的快慢
--cnt_0_test:out integer range 0 to 15
);
end led_88;
architecture behave of led_88 is
component gen_div is--分频元件调用声明
generic(div_param:integer:=2);--默认是4分频
port
(
clk:in std_logic;
bclk:out std_logic;
resetb:in std_logic
);
end component;
----
type data_88 is array(0 to 23) of std_logic_vector(7 downto 0);
constant led_data:data_88:=(X"77",X"B5",X"D5",X"E1",X"C5",X"B5",X"77",X"FF",X"7F",X"BF",X"DF",X"E1",X"C7",X"BF",X"7F",X"FF",X"FF",X"BD",X"BD",X"81",X"BD",X"BD",X"BD",X"FF");--"天""人"
这里的意思是显示三个字在8*8的点阵中但是显示的是4个字,而且第四个字未知 求解释,但是当显示2个或四个字的时候正常
signal clk_cnt:std_logic;--800Hz
signal sm_cmt:std_logic_vector(2 downto 0);--对clk_cnt计数,产生8个状态
signal delay:std_logic_vector(31 downto 0);--一个显示状态的暂留时间
signal cnt_0:integer range 0 to 23;
signal cnt_1:integer range 0 to 23;
signal cnt_2:integer range 0 to 23;
signal cnt_3:integer range 0 to 23;
signal cnt_4:integer range 0 to 23;
signal cnt_5:integer range 0 to 23;
signal cnt_6:integer range 0 to 23;
signal cnt_7:integer range 0 to 23;
signal LED:std_logic;
----
begin
--cnt_0_test<=cnt_0;
led_out<=LED;
--
gen_100k: --分频产生800hz脉冲
gen_div generic map(25000)--50000分频的,产生800Hz脉冲
port map--分频元件例化
(
clk=>clkin,
resetb=>not resetin,
bclk=>clk_cnt
);
----
gen_cnt_1k:--sm_cmt循环计数,产生显示扫描八个状态
process(clk_cnt,resetin)
begin
if resetin='0' then
sm_cmt<=B"000";
else
if rising_edge(clk_cnt) then
sm_cmt<=sm_cmt+'1';
end if;
end if;
end process;
Display:
process(clkin,sm_cmt,cnt_0,cnt_1,cnt_2,cnt_3,cnt_4,cnt_5,cnt_6,cnt_7,delay)
begin
if resetin='0' then
cnt_0<=0;--初始值各个指针,显示第一个汉字
cnt_1<=1;
cnt_2<=2;
cnt_3<=3;
cnt_4<=4;
cnt_5<=5;
cnt_6<=6;
cnt_7<=7;
delay<=X"00000000";
LED<='0';
else
if rising_edge(clkin) then
case sm_cmt is--循环扫描,不能停
when "000"=> line<="11111110";row<=led_data(cnt_0);--扫描显示当前的汉字
when "001"=> line<="11111101";row<=led_data(cnt_1);
when "010"=> line<="11111011";row<=led_data(cnt_2);
when "011"=> line<="11110111";row<=led_data(cnt_3);
when "100"=> line<="11101111";row<=led_data(cnt_4);
when "101"=> line<="11011111";row<=led_data(cnt_5);
when "110"=> line<="10111111";row<=led_data(cnt_6);
when "111"=> line<="01111111";row<=led_data(cnt_7);delay<=delay+'1';--扫描完一次后加1
when others=> null;
end case;
if delay=X"000FFFF0" then--切换到下一个显示状态,修改该值可改变滚动速度,值越大,速度越慢,反之亦然
cnt_0<=cnt_0+1;
cnt_1<=cnt_1+1;
cnt_2<=cnt_2+1;
cnt_3<=cnt_3+1;
cnt_4<=cnt_4+1;
cnt_5<=cnt_5+1;
cnt_6<=cnt_6+1;
cnt_7<=cnt_7+1;
delay<=X"00000000";
LED<= NOT LED;
end if;
end if;
end if;
end process;
end behave;
此帖出自
小平头技术问答
一周热门 更多>