Library IEEE;
Use IEEE.STD_LOGIC_1164.ALL;
Use IEEE.STD_LOGIC_ARITH.ALL;
Use IEEE.STD_LOGIC_UNSIGNED.ALL;
Entity lcd is
Port (
clock : in std_logic;
clear : in std_logic;
fm : in std_logic;
det : in std_logic;
mode_sel : in std_logic;
e : out std_logic;
rs : out std_logic;
wr : out std_logic;
data_out: out std_logic_vector(7 downto 0));
end lcd;
architecture sea of lcd is
Function num (x: integer) ---函数
return std_logic_vector is
variable num_return :std_logic_vector(7 downto 0);
begin
case x is
when 0 =>num_return:="00110000";
when 1 =>num_return:="00110001";
when 2 =>num_return:="00110010";
when 3 =>num_return:="00110011";
when 4 =>num_return:="00110100";
when 5 =>num_return:="00110101";
when 6 =>num_return:="00110110";
when 7 =>num_return:="00110111";
when 8 =>num_return:="00111000";
when 9 =>num_return:="00111001";
when 10 =>num_return:="01000001";--A
when 11 =>num_return:="01000010";--B
when 12 =>num_return:="01100011";--c
when 13 =>num_return:="01000100";--D
when 14 =>num_return:="01100101";--e
when 15 =>num_return:="01000110";--F
when 16 =>num_return:="01000111";--G
when 17 =>num_return:="01001000";--H
when 18 =>num_return:="01001001";--I
when 19 =>num_return:="01001010";--J
when 20 =>num_return:="01001011";--K
when 21 =>num_return:="01001100";--L
when 22 =>num_return:="01001101";--M
when 23 =>num_return:="01101110";--n
when 24 =>num_return:="01001111";--O
when 25 =>num_return:="01010000";--P
when 26 =>num_return:="01110001";--q
when 27 =>num_return:="01110010";--r
when 28 =>num_return:="01010011";--S
when 29 =>num_return:="01010100";--T
when 30 =>num_return:="01110101";--u
when 31 =>num_return:="01010110";--V
when 32 =>num_return:="01010111";--W
when 33 =>num_return:="01011000";--X
when 34 =>num_return:="01111001";--y
when 35 =>num_return:="01011010";--Z
when 36 =>num_return:="00111010";--:
when 37 =>num_return:="01111010";--z
when 38 =>num_return:="00101101";-- -
when 39 =>num_return:="01101111";--o
when 40 =>num_return:="00101110";--.
when 41 =>num_return:="00100000";--null
when 42 =>num_return:="01011110";--^
when 43 =>num_return:="01100010";--b
when 44 =>num_return:="01101001";--i
when 45 =>num_return:="01110000";--p
when 46 =>num_return:="01110011";--s
when 47 =>num_return:="01111000";--x
when 48 =>num_return:="01100100";--d
when 49 =>num_return:="01100101";--e
when others => null;
end case;
return num_return;
end num;
begin
P1:process(clock,clear,fm,det,mode_sel)
variable scan :integer range 87 downto 0:=0;
variable scan_clear :integer range 10 downto 0:=0;
variable scan_time : integer range 30000 downto 0:=0;
variable a : integer range 9 downto 0;
variable b : integer range 9 downto 0;
variable c : integer range 9 downto 0;
variable d : integer range 9 downto 0;
variable f : integer range 9 downto 0;
variable g : integer range 9 downto 0;
variable h : integer range 7 downto 1;
variable i : integer range 6 downto 0;
variable n1: integer range 42 downto 41;
variable n2: integer range 42 downto 41;
variable n3: integer range 42 downto 41;
variable n4: integer range 42 downto 41;
variable n5: integer range 42 downto 41;
variable n6: integer range 42 downto 41;
variable m1: integer range 50 downto 0;
variable m2: integer range 50 downto 0;
variable m3: integer range 50 downto 0;
variable m4: integer range 50 downto 0;
variable m5: integer range 50 downto 0;
variable m6: integer range 50 downto 0;
variable m7: integer range 50 downto 0;
variable m8: integer range 50 downto 0;
variable m9: integer range 50 downto 0;
variable m10: integer range 50 downto 0;
variable m11: integer range 50 downto 0;
variable m12: integer range 50 downto 0;
variable m13: integer range 50 downto 0;
variable m14: integer range 50 downto 0;
variable m15: integer range 50 downto 0;
variable m16: integer range 50 downto 0;
variable m17: integer range 50 downto 0;
variable m18: integer range 50 downto 0;
variable m19: integer range 50 downto 0;
variable m20: integer range 50 downto 0;
variable m21: integer range 50 downto 0;
variable m22: integer range 50 downto 0;
variable m23: integer range 50 downto 0;
variable m24: integer range 50 downto 0;
variable m25: integer range 50 downto 0;
variable m26: integer range 50 downto 0;
variable m27: integer range 50 downto 0;
variable m28: integer range 50 downto 0;
variable m29: integer range 50 downto 0;
variable m30: integer range 50 downto 0;
variable m31: integer range 50 downto 0;
variable m32: integer range 50 downto 0;
variable m33: integer range 50 downto 0;
variable m34: integer range 50 downto 0;
variable m35: integer range 50 downto 0;
variable m36: integer range 50 downto 0;
begin --进程开始
if rising_edge(clock) then scan_time:=scan_time+1;
if scan_time=30000 then scan_time:=0;scan:=scan+1;scan_clear:=scan_clear+1;
if scan=87 then scan:=0;
end if;
if scan_clear=10 then scan_clear:=0;
end if;
end if;
end if;
if clear='0' then i:=1;
elsif (det'event and det='1') then
i:=i+1;end if;if i=6 then i:=1;end if;
if clear='0' then i:=0;a:=0;b:=0;c:=0;d:=0;f:=1;g:=0;
elsif rising_edge(fm) then
case i is
when 0=>a:=a+1;if a>9 then a:=0;end if;
when 1=>b:=b+1;if b>9 then b:=0;a:=a+1;end if;
when 2=>c:=c+1;if c>9 then c:=0;b:=b+1;end if;if b>9 then b:=0;a:=a+1;end if;
when 3=>d:=d+1;if d>9 then d:=0;c:=c+1;end if;if c>9 then c:=0;b:=b+1;end if;if b>9 then b:=0;a:=a+1;end if;
when 4=>f:=f+1;if f>9 then f:=0;d:=d+1;end if;if d>9 then d:=0;c:=c+1;end if;if c>9 then c:=0;b:=b+1;end if;if b>9 then b:=0;a:=a+1;end if;
when 5=>g:=g+1;if g>9 then g:=0;f:=f+1;end if;if f>9 then f:=0;d:=d+1;end if;if d>9 then d:=0;c:=c+1;end if;if c>9 then c:=0;b:=b+1;end if;if b>9 then b:=0;a:=a+1;end if;
when others=>null;
end case;
end if;
if ((a*100000+b*10000+c*1000+d*100+f*10+g)>100000) then
a:=0;b:=0;c:=0;d:=0;f:=1;g:=0;
end if;
if clear='0' then h:=1;
elsif rising_edge(mode_sel) then h:=h+1;
if h=7 then h:=1;
end if;
end if;
case i is
when 0=>n1:=42;n2:=41;n3:=41;n4:=41;n5:=41;n6:=41;
when 1=>n1:=41;n2:=42;n3:=41;n4:=41;n5:=41;n6:=41;
when 2=>n1:=41;n2:=41;n3:=42;n4:=41;n5:=41;n6:=41;
when 3=>n1:=41;n2:=41;n3:=41;n4:=42;n5:=41;n6:=41;
when 4=>n1:=41;n2:=41;n3:=41;n4:=41;n5:=42;n6:=41;
when 5=>n1:=41;n2:=41;n3:=41;n4:=41;n5:=41;n6:=42;
when others=>null;
end case;
if clear='0' then i:=1;a:=0;b:=0;c:=0;d:=0;f:=1;g:=0;h:=1;
C1:case scan_clear is
when 0 =>rs<='0';wr<='0';e<='1';data_out<="00000001";
when 1 =>e<='0';
when 2 =>rs<='0';wr<='0';e<='1';data_out<="00000001";
when 3 =>e<='0';
when 4 =>rs<='0';wr<='0';e<='1';data_out<="00000001";
when 5 =>e<='0';
when 6 =>rs<='0';wr<='0';e<='1';data_out<="00000001";
when 7 =>e<='0';
when 8 =>rs<='0';wr<='0';e<='1';data_out<="00000001";
when 9 =>e<='0';
when others => null;
end case C1;
else
sel:case h is
when 1 =>m1:=28;m2:=44;m3:=23;m4:=47;m5:=36;m6:=41;m7:=41;m8:=41;m9:=41; --Sinx
m10:=a;m11:=b;m12:=c;m13:=d;m14:=f;m15:=40;m16:=g;m17:=20;m18:=17;
m19:=37;m20:=n1;m21:=n2;m22:=n3;m23:=n4;m24:=n5;m25:=41;m26:=n6;
m27:=41;m28:=41;m29:=41;m30:=41;m31:=41;m32:=41;m33:=41;m34:=41;m35:=41;m36:=41;
when 2 =>m1:=10;m2:=22;m3:=36;m4:=41;m5:=41;m6:=41;m7:=41;m8:=41;m9:=41; --AM
m10:=a;m11:=b;m12:= |