VHDL 16*16 点阵
本实验主要完成汉字字符在 LED 上的显示,16*16 扫描 LED 点阵的工作原
理与 8 位扫描数码管类似,只是显示的方式与结果不一样。本实验的示例程序
依次显示的是“湖南工程学院”,要求每隔一秒换下一个字显示。
源程序(带注释)
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
entity dzh is
port(
clk:in std_logic;
r,c:out std_logic_vector(15 downto 0));
end;
architecture two of dzh is
type states is(st0,st1,st2,st3,st4,st5);
signal cs,ns:states:=st0;
signal count:integer range 0 to 999:=0;
begin
a1:process(clk)
variable s:std_logic_vector(3 downto 0):="0000";
begin
if clk'event and clk='1' then
s:=s+1;
if cs=st0 then
case s is
--建立实体 dzh
--两个输出信号
--建立结构体 two
--定义六个状态
--“湖”字的显示
when "0000" =>r<=not"0000000000000001";c<=not"0111111111111111";
when "0001" =>r<=not"0000000000000010";c<=not"1011111011100000";
when "0010" =>r<=not"0000000000000100";c<=not"1100111011101110";
when "0011" =>r<=not"0000000000001000";c<=not"1111100000101110";
when "0100" =>r<=not"0000000000010000";c<=not"1111111011101110";
when "0101" =>r<=not"0000000000100000";c<=not"1111111011100000";
when "0110" =>r<=not"0000000001000000";c<=not"0011100000101110";
when "0111" =>r<=not"0000000010000000";c<=not"1100101110101110";
when "1000" =>r<=not"0000000100000000";c<=not"1111101110100000";
when "1001" =>r<=not"0000001000000000";c<=not"1111101110101110";
when "1010" =>r<=not"0000010000000000";c<=not"1111101110101110";
when "1011" =>r<=not"0000100000000000";c<=not"1110101110101110";
when "1100" =>r<=not"0001000000000000";c<=not"1101100000101110";
when "1101" =>r<=not"0010000000000000";c<=not"1011111111101110";
when "1110" =>r<=not"0100000000000000";c<=not"0111111111011100";
when "1111" =>r<=not"1000000000000000";c<=not"1111111111111111";
when others =>null;
end case;
elsif cs=st1 then
case s is
--“南”字的显示
when "0000" =>r<=not"0000000000000001";c<=not"1111111111111111";
when "0001" =>r<=not"0000000000000010";c<=not"1111111110111111";
when "0010" =>r<=not"0000000000000100";c<=not"1111111101111111";
when "0011" =>r<=not"0000000000001000";c<=not"1100000000000111";
when "0100" =>r<=not"0000000000010000";c<=not"1111111011111111";
when "0101" =>r<=not"0000000000100000";c<=not"1111110111111111";
when "0110" =>r<=not"0000000001000000";c<=not"1100000000000111";
when "0111" =>r<=not"0000000010000000";c<=not"1101101110110111";
when "1000" =>r<=not"0000000100000000";c<=not"1101110101110111";
when "1001" =>r<=not"0000001000000000";c<=not"1101100000110111";
when "1010" =>r<=not"0000010000000000";c<=not"1101111011110111";
when "1011" =>r<=not"0000100000000000";c<=not"1101000000010111";
when "1100" =>r<=not"0001000000000000";c<=not"1101111011110111";
when "1101" =>r<=not"0010000000000000";c<=not"1101111011100111";
when "1110" =>r<=not"0100000000000000";c<=not"1111111111111111";
when "1111" =>r<=not"1000000000000000";c<=not"1111111111111111";
when others =>null;
end case;
elsif cs=st2 then
case s is
--“工”字的显示
when "0000" =>r<=not"0000000000000001";c<=not"1111111111111111";
when "0001" =>r<=not"0000000000000010";c<=not"1111111111111111";
when "0010" =>r<=not"0000000000000100";c<=not"1111111111111111";
when "0011" =>r<=not"0000000000001000";c<=not"1100000000000111";
when "0100" =>r<=not"0000000000010000";c<=not"1111111011111111";
when "0101" =>r<=not"0000000000100000";c<=not"1111111011111111";
when "0110" =>r<=not"0000000001000000";c<=not"1111111011111111";
when "0111" =>r<=not"0000000010000000";c<=not"1111111011111111";
when "1000" =>r<=not"0000000100000000";c<=not"1111111011111111";
when "1001" =>r<=not"0000001000000000";c<=not"1111111011111111";
when "1010" =>r<=not"0000010000000000";c<=not"1111111011111111";
when "1011" =>r<=not"0000100000000000";c<=not"1111111011111111";
when "1100" =>r<=not"0001000000000000";c<=not"1100000000000111";
when "1101" =>r<=not"0010000000000000";c<=not"1111111111111111";
when "1110" =>r<=not"0100000000000000";c<=not"1111111111111111";
when "1111" =>r<=not"1000000000000000";c<=not"1111111111111111";
end case;
elsif cs=st3 then
case s is
--“程”字的显示
when "0000" =>r<=not"0000000000000001";c<=not"1111111111111111";
when "0001" =>r<=not"0000000000000010";c<=not"1111111111111111";
when "0010" =>r<=not"0000000000000100";c<=not"1111110110000011";
when "0011" =>r<=not"0000000000001000";c<=not"1100001110111011";
when "0100" =>r<=not"0000000000010000";c<=not"1111011110000011";
when "0101" =>r<=not"0000000000100000";c<=not"1111011111111111";
when "0110" =>r<=not"0000000001000000";c<=not"1000000100000001";
when "0111" =>r<=not"0000000010000000";c<=not"1110001111101111";
when "1000" =>r<=not"0000000100000000";c<=not"1101010111101111";
when "1001" =>r<=not"0000001000000000";c<=not"1101011010000011";
when "1010" =>r<=not"0000010000000000";c<=not"1011011111101111";
when "1011" =>r<=not"0000100000000000";c<=not"1111011111101111";
when "1100" =>r<=not"0001000000000000";c<=not"1111011111101111";
when "1101" =>r<=not"0010000000000000";c<=not"1111011100000001";
when "1110" =>r<=not"0100000000000000";c<=not"1111111111111111";
when "1111" =>r<=not"1000000000000000";c<=not"1111111111111111";
when others =>null;
end case;
elsif cs=st4 then
case s is
--“学”字的显示
when "0000" =>r<=not"0000000000000001";c<=not"1111111111111111";
when "0001" =>r<=not"0000000000000010";c<=not"1111011011110111";
when "0010" =>r<=not"0000000000000100";c<=not"1111101101101111";
when "0011" =>r<=not"0000000000001000";c<=not"1111111111111111";
when "0100" =>r<=not"0000000000010000";c<=not"1110000000000011";
when "0101" =>r<=not"0000000000100000";c<=not"1110111111111011";
when "0110" =>r<=not"0000000001000000";c<=not"1101110000010111";
when "0111" =>r<=not"0000000010000000";c<=not"1111111111011111";
when "1000" =>r<=not"0000000100000000";c<=not"1111111100111111";
when "1001" =>r<=not"0000001000000000";c<=not"1111111101111111";
when "1010" =>r<=not"0000010000000000";c<=not"1111100000001111";
when "1011" =>r<=not"0000100000000000";c<=not"1111111101111111";
when "1100" =>r<=not"0001000000000000";c<=not"1111111101111111";
when "1101" =>r<=not"0010000000000000";c<=not"1111111001111111";
when "1110" =>r<=not"0100000000000000";c<=not"1111111111111111";
when "1111" =>r<=not"1000000000000000";c<=not"1111111111111111";
when others =>null;
end case;
elsif cs=st5 then
case s is
--“院”字的显示
when "0000" =>r<=not"0000000000000001";c<=not"1111111110111111";
when "0001" =>r<=not"0000000000000010";c<=not"0000111111011111";
when "0010" =>r<=not"0000000000000100";c<=not"1011010000000001";
when "0011" =>r<=not"0000000000001000";c<=not"1011010111111101";
when "0100" =>r<=not"0000000000010000";c<=not"1010101111111011";
when "0101" =>r<=not"0000000000100000";c<=not"1001111100001111";
when "0110" =>r<=not"0000000001000000";c<=not"1010011111111111";
when "0111" =>r<=not"0000000010000000";c<=not"1011010000000011";
when "1000" =>r<=not"0000000100000000";c<=not"1011011101101111";
when "1001" =>r<=not"0000001000000000";c<=not"1000111101101111";
when "1010" =>r<=not"0000010000000000";c<=not"1011111101101111";
when "1011" =>r<=not"0000100000000000";c<=not"1011111011101101";
when "1100" =>r<=not"0001000000000000";c<=not"1011110111100001";
when "1101" =>r<=not"0010000000000000";c<=not"1011111111111111";
when "1110" =>r<=not"0100000000000000";c<=not"1111111111111111";
when "1111" =>r<=not"1000000000000000";c<=not"1111111111111111";
when others =>null;
end case;
else null;
end if;
end if;
end process a1;
a2:process(clk)
begin
if clk'event and clk='1' then
if count<999 then
count<=count+1;
else count<=0;
case cs is
when st0=>ns<=st1;
when st1=>ns<=st2;
--下一状态的转换
when st2=>ns<=st3;
when st3=>ns<=st4;
when st4=>ns<=st5;
when st5=>ns<=st0;
when others=>ns<=st0;
end case;
end if;
end if;
end process a2;
a3:process(clk)
begin
if clk'event and clk='1' then
cs<=ns;
end if;
end process a3;
end architecture;
--当前状态的转换