查看: 646|回复: 0
打印 上一主题 下一主题

VHDL 的5110液晶显示程序,全部源码。

[复制链接]
跳转到指定楼层
沙发
发表于 2016-5-18 22:44:35 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
FPGA描绘一个硬件电路构成的SPI总线。
貌似我这中写法50MHZ的主频下最快可以接近25Mbps的传输速率.
控制里加了个程序计数器和一个状态返回寄存器,模拟MCU,使控制起来方便一些。
从51的程序里搞了个ASCII码的字库进去,测试通过。
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;

entity lcd5110 is
port(mclk,reset:in std_logic;
      vccut std_logic;
      gndut std_logic;
      ledut std_logic;
      lcd_rstut std_logic;
      cs,sclk,mosi,cdut std_logic;
      miso:in std_logic
     
);

end entity;


architecture behav of lcd5110 is
signal cnt:integer range 0 to 255;
signal clk:std_logic;
type state is (clk_l,clk_h,clk_rising_edge,clk_falling_edge);
signal p:state:=clk_l;
type state2 is (idle,shift_data,shift_data1,clear_screen,set_xy,disp_char);
signal p2:state2:=idle;
signal p_back:state2;
signal data_reg:std_logic_vector(7 downto 0);
signal cnt2:integer range 0 to 8;
signal cnt3:integer range 0 to 65535;
signal cnt4:integer range 0 to 512;
signal char_reg:integer range 0 to 91;
signal y_reg:std_logic_vector(2 downto 0);
signal x_reg:std_logic_vector(6 downto 0);
type reg is array(0 to 5) of std_logic_vector(7 downto 0);
type reg2 is array (0 to 91) of reg;
constant ASCII:reg2:=(           
    (x"00", x"00", x"00", x"00", x"00", x"00"),   -- 0  sp
    (x"00", x"00", x"00", x"2f", x"00", x"00"),   -- 1  !  
    (x"00", x"00", x"07", x"00", x"07", x"00"),   -- 2  "
    (x"00", x"14", x"7f", x"14", x"7f", x"14"),   -- 3  #
    (x"00", x"24", x"2a", x"7f", x"2a", x"12"),   -- 4  $
    (x"00", x"62", x"64", x"08", x"13", x"23"),   -- 5  %
    (x"00", x"36", x"49", x"55", x"22", x"50"),   -- 6  &
    (x"00", x"00", x"05", x"03", x"00", x"00"),   -- 7  '
    (x"00", x"00", x"1c", x"22", x"41", x"00"),   -- 8  (
    (x"00", x"00", x"41", x"22", x"1c", x"00"),   -- 9  )
    (x"00", x"14", x"08", x"3E", x"08", x"14"),   -- 10 *
    (x"00", x"08", x"08", x"3E", x"08", x"08"),   -- 11 +
    (x"00", x"00", x"00", x"A0", x"60", x"00"),   -- 12 ",
    (x"00", x"08", x"08", x"08", x"08", x"08"),   -- 13 -
    (x"00", x"00", x"60", x"60", x"00", x"00"),   -- 14 .
    (x"00", x"20", x"10", x"08", x"04", x"02"),   -- 15 /
    (x"00", x"3E", x"51", x"49", x"45", x"3E"),   -- 16 0
    (x"00", x"00", x"42", x"7F", x"40", x"00"),   -- 17 1
    (x"00", x"42", x"61", x"51", x"49", x"46"),   -- 18 2
    (x"00", x"21", x"41", x"45", x"4B", x"31"),   -- 19 3
    (x"00", x"18", x"14", x"12", x"7F", x"10"),   -- 20 4
    (x"00", x"27", x"45", x"45", x"45", x"39"),   -- 21 5
    (x"00", x"3C", x"4A", x"49", x"49", x"30"),   -- 22 6
    (x"00", x"01", x"71", x"09", x"05", x"03"),   -- 23 7
    (x"00", x"36", x"49", x"49", x"49", x"36"),   -- 24 8
    (x"00", x"06", x"49", x"49", x"29", x"1E"),   -- 25 9
    (x"00", x"00", x"36", x"36", x"00", x"00"),   -- 26 :
    (x"00", x"00", x"56", x"36", x"00", x"00"),   -- 27 ;
    (x"00", x"08", x"14", x"22", x"41", x"00"),   -- 28 <
    (x"00", x"14", x"14", x"14", x"14", x"14"),   -- 29 =
    (x"00", x"00", x"41", x"22", x"14", x"08"),   -- 30 >
    (x"00", x"02", x"01", x"51", x"09", x"06"),   -- 31 ?
    (x"00", x"32", x"49", x"59", x"51", x"3E"),   -- 32 @
    (x"00", x"7C", x"12", x"11", x"12", x"7C"),   -- 33 A
    (x"00", x"7F", x"49", x"49", x"49", x"36"),   -- 34 B
    (x"00", x"3E", x"41", x"41", x"41", x"22"),   -- 35 C
    (x"00", x"7F", x"41", x"41", x"22", x"1C"),   -- 36 D
    (x"00", x"7F", x"49", x"49", x"49", x"41"),   -- 37 E
    (x"00", x"7F", x"09", x"09", x"09", x"01"),   -- 38 F
    (x"00", x"3E", x"41", x"49", x"49", x"7A"),   -- 39 G
    (x"00", x"7F", x"08", x"08", x"08", x"7F"),   -- 40 H
    (x"00", x"00", x"41", x"7F", x"41", x"00"),   -- 41 I
    (x"00", x"20", x"40", x"41", x"3F", x"01"),   -- 42 J
    (x"00", x"7F", x"08", x"14", x"22", x"41"),   -- 43 K
    (x"00", x"7F", x"40", x"40", x"40", x"40"),   -- 44 L
    (x"00", x"7F", x"02", x"0C", x"02", x"7F"),   -- 45 M
    (x"00", x"7F", x"04", x"08", x"10", x"7F"),   -- 46 N
    (x"00", x"3E", x"41", x"41", x"41", x"3E"),   -- 47 O
    (x"00", x"7F", x"09", x"09", x"09", x"06"),   -- 48 P
    (x"00", x"3E", x"41", x"51", x"21", x"5E"),   -- 49 Q
    (x"00", x"7F", x"09", x"19", x"29", x"46"),   -- 50 R
    (x"00", x"46", x"49", x"49", x"49", x"31"),   -- 51 S
    (x"00", x"01", x"01", x"7F", x"01", x"01"),   -- 52 T
    (x"00", x"3F", x"40", x"40", x"40", x"3F"),   -- 53 U
    (x"00", x"1F", x"20", x"40", x"20", x"1F"),   -- 54 V
    (x"00", x"3F", x"40", x"38", x"40", x"3F"),   -- 55 W
    (x"00", x"63", x"14", x"08", x"14", x"63"),   -- 56 X
    (x"00", x"07", x"08", x"70", x"08", x"07"),   -- 57 Y
    (x"00", x"61", x"51", x"49", x"45", x"43"),   -- 58 Z
    (x"00", x"00", x"7F", x"41", x"41", x"00"),   -- 59 [
    (x"00", x"55", x"2A", x"55", x"2A", x"55"),   -- 60 55
    (x"00", x"00", x"41", x"41", x"7F", x"00"),   -- 61 ]
    (x"00", x"04", x"02", x"01", x"02", x"04"),   -- 62 ^
    (x"00", x"40", x"40", x"40", x"40", x"40"),   -- 63 _
    (x"00", x"00", x"01", x"02", x"04", x"00"),   -- 64 '
    (x"00", x"20", x"54", x"54", x"54", x"78"),   -- 65 a
    (x"00", x"7F", x"48", x"44", x"44", x"38"),   -- 66 b
    (x"00", x"38", x"44", x"44", x"44", x"20"),   -- 67 c
    (x"00", x"38", x"44", x"44", x"48", x"7F"),   -- 68 d
    (x"00", x"38", x"54", x"54", x"54", x"18"),   -- 69 e
    (x"00", x"08", x"7E", x"09", x"01", x"02"),   -- 70 f
    (x"00", x"18", x"A4", x"A4", x"A4", x"7C"),   -- 71 g
    (x"00", x"7F", x"08", x"04", x"04", x"78"),   -- 72 h
    (x"00", x"00", x"44", x"7D", x"40", x"00"),   -- 73 i
    (x"00", x"40", x"80", x"84", x"7D", x"00"),   -- 74 j
    (x"00", x"7F", x"10", x"28", x"44", x"00"),   -- 75 k
    (x"00", x"00", x"41", x"7F", x"40", x"00"),   -- 76 l
    (x"00", x"7C", x"04", x"18", x"04", x"78"),   -- 77 m
    (x"00", x"7C", x"08", x"04", x"04", x"78"),   -- 78 n
    (x"00", x"38", x"44", x"44", x"44", x"38"),   -- 79 o
    (x"00", x"FC", x"24", x"24", x"24", x"18"),   -- 80 p
    (x"00", x"18", x"24", x"24", x"18", x"FC"),   -- 81 q
    (x"00", x"7C", x"08", x"04", x"04", x"08"),   -- 82 r
    (x"00", x"48", x"54", x"54", x"54", x"20"),   -- 83 s
    (x"00", x"04", x"3F", x"44", x"40", x"20"),   -- 84 t
    (x"00", x"3C", x"40", x"40", x"20", x"7C"),   -- 85 u
    (x"00", x"1C", x"20", x"40", x"20", x"1C"),   -- 86 v
    (x"00", x"3C", x"40", x"30", x"40", x"3C"),   -- 87 w
    (x"00", x"44", x"28", x"10", x"28", x"44"),   -- 88 x
    (x"00", x"1C", x"A0", x"A0", x"A0", x"7C"),   -- 89 y
    (x"00", x"44", x"64", x"54", x"4C", x"44"),   -- 90 z
    (x"14", x"14", x"14", x"14", x"14", x"14")    -- 91 horiz lines
);


constant ONN:std_logic:='0';
constant OFF:std_logic:='1';
constant CMD:std_logic:='0';
constant DATA:std_logic:='1';

begin
sclk<=clk;
vcc<='1';
gnd<='0';
led<='1';
lcd_rst<='1';



process (mclk)   ---div clk
begin
if mclk'event and mclk='1'
then if reset='0'
then cnt<=0;
else cnt<=cnt+1;
if cnt=49 then
cnt<=0;
end if;
if cnt<25 then
clk<='0';
else clk<='1';
end if;
end if;
end if;
end process ;


process (mclk)  
begin
if mclk'event and mclk='1'
then if reset='0'
then p<=clk_l;


else

case p is
when clk_l =>
if clk='1' then
p<=clk_rising_edge;
else p<=clk_l;
end if;

when clk_rising_edge=>
p<=clk_h;

when clk_h=>
if clk='0' then
p<=clk_falling_edge;
else p<=clk_h;
end if;

when clk_falling_edge=>
p<=clk_l;

when others =>null;
end case ;
end if;
end if;
end process;



process(mclk)                       

begin
if mclk'event and mclk='1'
then if reset='0'
then p2<=idle;
     cs<=OFF;
     cnt3<=0;
else

case p2 is
when idle =>
cs<=OFF;
cnt3<=cnt3+1;
case cnt3 is
when 0=> data_reg<=x"21";cd<=CMD;p2<=shift_data;p_back<=idle;
when 1=> data_reg<=x"c8";cd<=CMD;p2<=shift_data;p_back<=idle;
when 2=> data_reg<=x"06";cd<=CMD;p2<=shift_data;p_back<=idle;
when 3=> data_reg<=x"13";cd<=CMD;p2<=shift_data;p_back<=idle;
when 4=> data_reg<=x"20";cd<=CMD;p2<=shift_data;p_back<=idle;
when 5=> p2<=clear_screen;p_back<=clear_screen;
when 6=> data_reg<=x"0c";cd<=CMD;p2<=shift_data;p_back<=idle;
when 7=> p2<=set_xy;p_back<=set_xy;y_reg<="010";x_reg<="0000110";
when 8=> p2<=disp_char;p_back<=disp_char;char_reg<=40;  --H
when 9=> p2<=disp_char;p_back<=disp_char;char_reg<=69;  --e
when 10=> p2<=disp_char;p_back<=disp_char;char_reg<=76; --l
when 11=> p2<=disp_char;p_back<=disp_char;char_reg<=76; --l
when 12=> p2<=disp_char;p_back<=disp_char;char_reg<=79; --o
when 13=> p2<=disp_char;p_back<=disp_char;char_reg<=0;  --
when 14=> p2<=disp_char;p_back<=disp_char;char_reg<=55; --W
when 15=> p2<=disp_char;p_back<=disp_char;char_reg<=79; --o
when 16=> p2<=disp_char;p_back<=disp_char;char_reg<=82; --r
when 17=> p2<=disp_char;p_back<=disp_char;char_reg<=76; --l
when 18=> p2<=disp_char;p_back<=disp_char;char_reg<=68; --d
when 19=> p2<=disp_char;p_back<=disp_char;char_reg<=1;  --!
when 20=> p2<=set_xy;p_back<=set_xy;y_reg<="011";x_reg<="0011011";
when 21=> p2<=disp_char;p_back<=disp_char;char_reg<=18;  --2
when 22=> p2<=disp_char;p_back<=disp_char;char_reg<=16;  --0
when 23=> p2<=disp_char;p_back<=disp_char;char_reg<=17;  --1
when 24=> p2<=disp_char;p_back<=disp_char;char_reg<=16;  --0

when 25=>cnt3<=25;

when others=>null;
end case;

when shift_data=>
if p=clk_falling_edge then   --falling edge output
   if cnt2=8 then
      cnt2<=0;
      p2<=p_back;
   else
   p2<=shift_data1;
   cs<=ONN;
   mosi<=data_reg(7);
   end if;
else p2<=shift_data;
end if;


when shift_data1=>
if p=clk_rising_edge then   --rising edge input
   data_reg<=data_reg(6 downto 0)& miso;
   cnt2<=cnt2+1;
   p2<=shift_data;
else
   p2<=shift_data1;
end if;

when clear_screen=>
data_reg<=x"00";
cnt4<=cnt4+1;
cs<=OFF;
cd<=DATA;
if cnt4=504
then cnt4<=0;
p2<=idle;
else
p2<=shift_data;
end if;

when set_xy=>
cnt4<=cnt4+1;
cs<=OFF;
cd<=CMD;
case cnt4 is
when 0 => data_reg<=x"40" or y_reg;p2<=shift_data;
when 1 => data_reg<=x"80" or x_reg;p2<=shift_data;
when 2 => p2<=idle;cnt4<=0;
when others =>null;
end case;

when disp_char=>
cnt4<=cnt4+1;
cs<=OFF;
cd<=DATA;
if cnt4=6
then  p2<=idle;cnt4<=0;
else  data_reg<=ASCII(char_reg)(cnt4);
      p2<=shift_data;
end if;

when others => null;
end case;
end if;
end if;
end process;

end behav ;

(原文件名:31012010(002).jpg)

点击此处下载 ourdev_531236.rar(文件大小:1.17M) (原文件名:5110.rar)







回复

使用道具 举报

您需要登录后才可以回帖 登录 | 加入因仑

本版积分规则

快速回复 返回顶部 返回列表