📄 12864.txt
字号:
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
use IEEE.STD_LOGIC_ARITH.ALL;
entity LCD is
generic(divide_to_100k:integer:=100000);
port(clk:in std_logic;
rw,rs,e,lcd_rst:out std_logic;
lcd_data:out std_logic_vector(7 downto 0));
end LCD ;
architecture tcl of LCD is
signal clk_100k:std_logic;
type state is(s0,s1,s2,s3,s4,s5,s6,s7,s8,s9,s10);
signal current_s:state;
type data_buffer is array(0 to 15)of std_logic_vector(7 downto 0);
constant data_buf:data_buffer:=(x"d2",x"ba",x"be",x"a7",
x"cf", x"d4",x"ca",x"be",x"c4",
x"a3",x"bf",x"e9",x"c9",
x"e8",x"bc",x"c6");
begin
--U1:divclk1 port map(clk,clk_100k);
process(clk)
variable cnt:integer range 0 to divide_to_100k;
begin
if(clk'event and clk='1')then cnt:=cnt+1;
if(cnt=divide_to_100k)then cnt:=0;
end if;
if(cnt<divide_to_100k/2) then clk_100k<='0';
else clk_100k<='1';
end if;
end if;
end process;
process(clk_100k)
variable cnt1:integer range 0 to 10000;
variable cnt_1:integer range 0 to 1000;
variable code_cnt:integer range 0 to 13;
variable data_cnt:integer range 0 to 480;
begin
if(clk_100k'event and clk_100k='1')then
case current_s is
when s0=>rw<='1';rs<='1';e<='1';cnt1:=cnt1+1;
if cnt1<500 then lcd_rst<='0';
elsif cnt1<1000 then lcd_rst<='1';
elsif cnt1=1000 then
lcd_rst<='1';cnt1:=0;current_s<=s1;
end if;
when s1=>cnt_1:=cnt_1+1;
if cnt_1<1*3 then e<='1';rs<='0';rw<='0';
elsif cnt_1<2*3 then lcd_data<=x"0c";
elsif cnt_1<10*3 then e<='0';
elsif cnt_1=10*3 then cnt_1:=0;current_s<=s2;
end if;
when s2=>cnt_1:=cnt_1+1;
if cnt_1<1*3 then e<='1';rs<='0';rw<='0';
elsif cnt_1<2*3 then lcd_data<=x"80";
elsif cnt_1<10*3 then e<='0';
elsif cnt_1=10*3 then cnt_1:=0;current_s<=s3;
end if;
when s3=>
if cnt_1<1*3 then e<='1';rs<='1';rw<='0';
elsif cnt_1<2*3 then lcd_data<=data_buf(data_cnt);
elsif cnt_1=2*3 then data_cnt:=data_cnt+1;
elsif cnt_1<100 then e<='0';
end if;
cnt_1:=cnt_1+1;
if cnt_1=100 then cnt_1:=0;
if data_cnt=16 then current_s<=s4;
data_cnt:=0;
end if;
end if;
when s4=>cnt_1:=cnt_1+1;
if cnt_1<1*3 then e<='1';rs<='0';rw<='0';
elsif cnt_1<2*3 then lcd_data<=x"88";
elsif cnt_1<10*3 then e<='0';
elsif cnt_1=10*3 then cnt_1:=0;current_s<=s5;
end if;
when s5=>
if cnt_1<1*3 then e<='1';rs<='1';rw<='0';
elsif cnt_1<2*3 then lcd_data<=data_buf(data_cnt);
elsif cnt_1=2*3 then data_cnt:=data_cnt+1;
elsif cnt_1<100 then e<='0';
end if;
cnt_1:=cnt_1+1;
if cnt_1=100 then cnt_1:=0;
if data_cnt=16 then current_s<=s4;
data_cnt:=0;
end if;
end if;
when s6=>NULL;
when others=>current_s<=s0;
end case;
end if;
end process;
end tcl;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -