📄 lcd.vhd
字号:
------------------------------------------------------------------------------------ Company: -- Engineer: -- -- Create Date: 15:46:19 04/17/2006 -- Design Name: -- Module Name: LCD - Behavioral -- Project Name: -- Target Devices: -- Tool versions: -- Description: ---- Dependencies: ---- Revision: -- Revision 0.01 - File Created-- Additional Comments: ------------------------------------------------------------------------------------library IEEE;use IEEE.STD_LOGIC_1164.ALL;use IEEE.STD_LOGIC_ARITH.ALL;use IEEE.STD_LOGIC_UNSIGNED.ALL;---- Uncomment the following library declaration if instantiating---- any Xilinx primitives in this code.--library UNISIM;--use UNISIM.VComponents.all;entity LCD is generic(divide_to_100k:integer:=500); Port ( clk,rst : in STD_LOGIC; s0_a,s1_a,s2_a,s3_a,s4_a,s5_a,s6_a: out std_logic; c1,c2: out STD_LOGIC; wr : out STD_LOGIC; rd : out STD_LOGIC; cd : out STD_LOGIC; lcd_rst : out STD_LOGIC; lcd_data : out STD_LOGIC_VECTOR (7 downto 0));end LCD;architecture Behavioral of LCD issignal clk_100k:std_logic;type state is (s0,s1,s2,s3,s4,s5,s6,s7,s8,s9,s10,s11,s12,s13,s14,s15); signal current_s:state;--type state_s is (s0_0,s1_1,s2_2);--signal current_s_s:state_s;type instruction_code is array(0 to 12)of std_logic_vector(7 downto 0);constant c_code:instruction_code:=(x"00",x"00",x"40",x"1e",x"00",x"41",x"80",x"94",x"07",x"00",x"24",x"b0",x"b2"); --c_t_starting_add --c_t_width --c_t_on --c_add_p c_auto_w_off --c_or_mode c_auto_w_ontype data_buffer is array(0 to 14)of std_logic_vector(7 downto 0);constant data_buf:data_buffer:=(x"57",x"57",x"57",x"0E", x"13",x"11",x"15",x"59", x"44",x"44",x"5A",x"0E", x"43",x"4F",x"4D"); beginc1<='1';c2<='1';process(clk)variable cnt:integer range 0 to divide_to_100k; begin if rising_edge(clk) 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)-------------clk_100kvariable cnt1:integer range 0 to 500000; --cnt1 for loopvariable cnt1_1:integer range 0 to 1000; --cnt1_1 for writing operationvariable code_cnt:integer range 0 to 13; --cnt1_2 array of codevariable data_cnt:integer range 0 to 480; begin if rising_edge(clk_100k) then if rst='1' then current_s<=s0; cnt1:=0; cnt1_1:=0; code_cnt:=0; data_cnt:=0; lcd_rst<='0'; s0_a<='0'; s1_a<='0'; s2_a<='0'; s3_a<='0'; s4_a<='0'; s5_a<='0'; s6_a<='0'; else case current_s is when s0=> wr<='1'; rd<='1'; cnt1:=cnt1+1; if cnt1<250000 then lcd_rst<='0'; elsif cnt1<500000 then--500 lcd_rst<='1'; elsif cnt1=500000 then--500 --delay for lcd_initial lcd_rst<='1'; cnt1:=0; current_s<=s1; end if; s0_a<='0'; s1_a<='1'; s2_a<='1'; s3_a<='1'; s4_a<='1'; s5_a<='1'; s6_a<='1'; when s1=> if cnt1<2 then --control amount of c_code if cnt1_1<1*3 then cd<='0'; elsif cnt1_1<2*3 then lcd_data<=c_code(code_cnt); if cnt1_1=(2*3-1) then code_cnt:=code_cnt+1; end if; elsif cnt1_1<3*3 then wr<='0'; elsif cnt1_1<4*3 then wr<='1'; -----------------------------writing a parameter elsif cnt1_1<5*3 then cd<='0'; elsif cnt1_1<6*3 then lcd_data<=c_code(code_cnt); if cnt1_1=6*3-1 then code_cnt:=code_cnt+1; end if; elsif cnt1_1<7*3 then wr<='0'; elsif cnt1_1<8*3 then wr<='1'; -----------------------------writing a parameter elsif cnt1_1<9*3 then cd<='1'; elsif cnt1_1<10*3 then lcd_data<=c_code(code_cnt); if cnt1_1=10*3-1 then code_cnt:=code_cnt+1; end if; elsif cnt1_1<11*3 then wr<='0'; elsif cnt1_1<12*3 then wr<='1'; end if; end if; -----------------------------writing a code cnt1_1:=cnt1_1+1; if cnt1_1=100 then cnt1_1:=0; cnt1:=cnt1+1; if cnt1=2 then current_s<=s2; cnt1:=0; end if; end if; s0_a<='1'; s1_a<='0'; s2_a<='1'; s3_a<='1'; s4_a<='1'; s5_a<='1'; s6_a<='1'; when s2=> if cnt1<2 then --control amount of c_code if cnt1_1<1*3 then cd<='1'; elsif cnt1_1<2*3 then lcd_data<=c_code(code_cnt); if cnt1_1=2*3-1 then code_cnt:=code_cnt+1; end if; elsif cnt1_1<3*3 then wr<='0'; elsif cnt1_1<4*3 then wr<='1'; end if; end if; -----------------------------writing a code cnt1_1:=cnt1_1+1; if cnt1_1=100 then cnt1_1:=0; cnt1:=cnt1+1; if cnt1=2 then current_s<=s3; cnt1:=0; end if; end if; s0_a<='1'; s1_a<='1'; s2_a<='0'; s3_a<='1'; s4_a<='1'; s5_a<='1'; s6_a<='1'; when s3=>-------------------------set add_p and auto_write if cnt1_1<1*3 then cd<='0'; elsif cnt1_1<2*3 then lcd_data<=c_code(8); elsif cnt1_1<3*3 then wr<='0'; elsif cnt1_1<4*3 then wr<='1'; -----------------------------writing a parameter elsif cnt1_1<5*3 then cd<='0'; elsif cnt1_1<6*3 then lcd_data<=c_code(9); elsif cnt1_1<7*3 then wr<='0'; elsif cnt1_1<8*3 then wr<='1'; -----------------------------writing a parameter elsif cnt1_1<9*3 then cd<='1'; elsif cnt1_1<10*3 then lcd_data<=c_code(10); elsif cnt1_1<11*3 then wr<='0'; elsif cnt1_1<12*3 then wr<='1'; end if; -----------------------------writing a code cnt1_1:=cnt1_1+1; if cnt1_1=100 then cnt1_1:=0; current_s<=s4; end if; s0_a<='1'; s1_a<='1'; s2_a<='1'; s3_a<='0'; s4_a<='1'; s5_a<='1'; s6_a<='1'; when s4=> if cnt1_1<1*3 then cd<='1'; elsif cnt1_1<2*3 then lcd_data<=c_code(11); elsif cnt1_1<5*3 then wr<='0'; elsif cnt1_1<6*3 then wr<='1'; end if; -----------------------------writing a code cnt1_1:=cnt1_1+1; if cnt1_1=100 then cnt1_1:=0; current_s<=s5; data_cnt:=0; end if; s0_a<='1'; s1_a<='1'; s2_a<='1'; s3_a<='1'; s4_a<='0'; s5_a<='1'; s6_a<='1'; when s5=> if cnt1_1<1*3 then cd<='0'; elsif cnt1_1<2*3 then lcd_data<=x"37"; data_cnt:=data_cnt+1; elsif cnt1_1<3*3 then wr<='0'; elsif cnt1_1<4*3 then wr<='1'; end if; -----------------------------writing a data cnt1_1:=cnt1_1+1; if cnt1_1=100 then cnt1_1:=0; if data_cnt=480 then current_s<=s6; data_cnt:=0; end if; end if; s0_a<='1'; s1_a<='1'; s2_a<='1'; s3_a<='1'; s4_a<='1'; s5_a<='0'; s6_a<='1'; when s6=> if cnt1_1<1*3 then cd<='1'; elsif cnt1_1<2*3 then lcd_data<=c_code(12); elsif cnt1_1<3*3 then wr<='0'; elsif cnt1_1<4*3 then wr<='1'; end if; -----------------------------writing a code cnt1_1:=cnt1_1+1; if cnt1_1=100 then cnt1_1:=0;---------------------------------------------------------- current_s<=s7;-------------------------------------------------------- end if; s0_a<='1'; s1_a<='1'; s2_a<='1'; s3_a<='1'; s4_a<='1'; s5_a<='1'; s6_a<='0'; when s7=>-------------------------set add_p and auto_write if cnt1_1=0 then cd<='0'; elsif cnt1_1=1 then lcd_data<=x"00"; elsif cnt1_1=2 then wr<='0'; elsif cnt1_1=3 then wr<='1'; -----------------------------writing a parameter elsif cnt1_1=4 then cd<='0'; elsif cnt1_1=5 then lcd_data<=x"00"; elsif cnt1_1=6 then wr<='0'; elsif cnt1_1=7 then wr<='1'; -----------------------------writing a parameter elsif cnt1_1=8 then cd<='1'; elsif cnt1_1=9 then lcd_data<=c_code(10); elsif cnt1_1=10 then wr<='0'; elsif cnt1_1=11 then wr<='1'; end if; -----------------------------writing a code cnt1_1:=cnt1_1+1; if cnt1_1=100 then cnt1_1:=0; current_s<=s8; end if; s0_a<='1'; s1_a<='1'; s2_a<='1'; s3_a<='0'; s4_a<='1'; s5_a<='1'; s6_a<='1'; when s8=> if cnt1_1=0 then cd<='1'; elsif cnt1_1=1 then lcd_data<=c_code(11); elsif cnt1_1=2 then wr<='0'; elsif cnt1_1=3 then wr<='1'; end if; -----------------------------writing a code cnt1_1:=cnt1_1+1; if cnt1_1=100 then cnt1_1:=0; current_s<=s9; data_cnt:=0; end if; s0_a<='1'; s1_a<='1'; s2_a<='1'; s3_a<='1'; s4_a<='0'; s5_a<='1'; s6_a<='1'; when s9=> if cnt1_1=0 then cd<='0'; elsif cnt1_1=1 then lcd_data<=x"00"; data_cnt:=data_cnt+1; elsif cnt1_1=2 then wr<='0'; elsif cnt1_1=3 then wr<='1'; end if; -----------------------------writing a data cnt1_1:=cnt1_1+1; if cnt1_1=100 then cnt1_1:=0; if data_cnt=480 then current_s<=s10; data_cnt:=0; end if; end if; s0_a<='1'; s1_a<='1'; s2_a<='1'; s3_a<='1'; s4_a<='1'; s5_a<='0'; s6_a<='1'; when s10=> if cnt1_1=0 then cd<='1'; elsif cnt1_1=1 then lcd_data<=c_code(12); elsif cnt1_1=2 then wr<='0'; elsif cnt1_1=3 then wr<='1'; end if; -----------------------------writing a code cnt1_1:=cnt1_1+1; if cnt1_1=100 then cnt1_1:=0;---------------------------------------------------------- current_s<=s11;-------------------------------------------------------- end if; s0_a<='1'; s1_a<='1'; s2_a<='1'; s3_a<='1'; s4_a<='1'; s5_a<='1'; s6_a<='0'; when s11=>-------------------------set add_p and auto_write if cnt1_1=0 then cd<='0'; elsif cnt1_1=1 then lcd_data<=c_code(8); elsif cnt1_1=2 then wr<='0'; elsif cnt1_1=3 then wr<='1'; -----------------------------writing a parameter elsif cnt1_1=4 then cd<='0'; elsif cnt1_1=5 then lcd_data<=c_code(9); elsif cnt1_1=6 then wr<='0'; elsif cnt1_1=7 then wr<='1'; -----------------------------writing a parameter elsif cnt1_1=8 then cd<='1'; elsif cnt1_1=9 then lcd_data<=c_code(10); elsif cnt1_1=10 then wr<='0'; elsif cnt1_1=11 then wr<='1'; end if; -----------------------------writing a code cnt1_1:=cnt1_1+1; if cnt1_1=100 then cnt1_1:=0; current_s<=s12; end if; s0_a<='1'; s1_a<='1'; s2_a<='1'; s3_a<='0'; s4_a<='1'; s5_a<='1'; s6_a<='1'; when s12=> if cnt1_1=0 then cd<='1'; elsif cnt1_1=1 then lcd_data<=c_code(11); elsif cnt1_1=2 then wr<='0'; elsif cnt1_1=3 then wr<='1'; end if; -----------------------------writing a code cnt1_1:=cnt1_1+1; if cnt1_1=100 then cnt1_1:=0; current_s<=s13; data_cnt:=0; end if; s0_a<='1'; s1_a<='1'; s2_a<='1'; s3_a<='1'; s4_a<='0'; s5_a<='1'; s6_a<='1'; when s13=> if cnt1_1=0 then cd<='0'; elsif cnt1_1=1 then lcd_data<=data_buf(data_cnt); data_cnt:=data_cnt+1; elsif cnt1_1=2 then wr<='0'; elsif cnt1_1=3 then wr<='1'; end if; -----------------------------writing a data cnt1_1:=cnt1_1+1; if cnt1_1=100 then cnt1_1:=0; if data_cnt=15 then current_s<=s14; data_cnt:=0; end if; end if; s0_a<='1'; s1_a<='1'; s2_a<='1'; s3_a<='1'; s4_a<='1'; s5_a<='0'; s6_a<='1'; when s14=> if cnt1_1=0 then cd<='1'; elsif cnt1_1=1 then lcd_data<=c_code(12); elsif cnt1_1=2 then wr<='0'; elsif cnt1_1=3 then wr<='1'; end if; -----------------------------writing a code cnt1_1:=cnt1_1+1; if cnt1_1=100 then cnt1_1:=0;---------------------------------------------------------- current_s<=s15;-------------------------------------------------------- end if; s0_a<='1'; s1_a<='1'; s2_a<='1'; s3_a<='1'; s4_a<='1'; s5_a<='1'; s6_a<='0'; when s15=> null; when others=> current_s<=s0; end case; end if; end if;end process; end Behavioral;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -