FPGA-1602
0赞
发表于 6/27/2011 10:57:20 AM
阅读(2328)
1602基本液晶显示屏,学会对1602操作,编程能力会更进一步的,下面我将自己的代码放在下面,仅供参考。
library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; use ieee.std_logic_arith.all; entity lcd1602 is port ( clk: in std_logic; rs,rw,en: out std_logic; beer: out bit; lcd_date: out std_logic_vector(7 downto 0) ); -- rest: out std_logic); end lcd1602; architecture xianshi of lcd1602 is type state is(s0,s1,s2,s3,s4,s5,s6,s7,s8,s9,sa,sb,sc,sd,se,sf,sg,sh,si,sj); --s1 显示模式设置状态 38H --s2 显示关闭状态 08H --s3 显示清屏状态 01H --s4 显示开,光标设置 0cH --s5 显示光标移动状态 06H --S6 写地址状态,显示在哪行与列 --s7 写数据状态 signal current_state: state; signal lcd_clk: std_logic; signal count: integer range 0 to 2500000; -- signal cnt: integer range 0 to 3; begin beer <= '1'; en <= lcd_clk; rw <= '0'; end process(clk)-- 产生lcd_clk begin if clk'event and clk='1' then if count = 2500000 then count <= 0; -- cnt <= cnt+1; lcd_clk <= not lcd_clk; else count <= count+1; end if; end if; end process; process(clk,lcd_clk) begin if lcd_clk'event and lcd_clk='1' then rs<='0'; case current_state is when s0=>lcd_date<="00111000";--显示模式设置状态 38H current_state<=s1; when s1=>lcd_date<="00001000";-- 显示关闭状态 08H current_state<=s2; when s2=>lcd_date<="00000001";-- 显示清屏状态 01H current_state<=s3; when s3=>lcd_date<="00001100";--显示开,光标设置 0cH current_state<=s4; when s4=>lcd_date<="00000110";--显示光标移动状态 current_state<=s5; when s5=>lcd_date<="10000001";--写地址状态,显示在哪行与列 入口地址 current_state<=s6; when s6=>rs<='1';----写数据,字符W lcd_date<="01010111"; -- when 3=>lcd_date<="01000011"; current_state<=s7;when s7=>rs<='1';----写数据,字符W lcd_date<="01010111"; current_state<=s8; when s8=>rs<='1';----写数据,字符W lcd_date<="01010111"; current_state<=s9; when s9=>rs<='1';----写数据,字符. lcd_date<="00101110"; current_state<=sa; when sa=>rs<='1';----写数据,字符L lcd_date<="01001100"; current_state<=sb; when sb=>rs<='1';----写数据,字符J lcd_date<="01001010"; current_state<=sc; when sc=>rs<='1';----写数据,字符D lcd_date<="01000100"; current_state<=sd; when sd=>rs<='1';----写数据,字符X lcd_date<="01011000"; current_state<=se; when se=>rs<='1';----写数据,字符. lcd_date<="00101110"; current_state<=sf; when sf=>rs<='1';----写数据,字符C lcd_date<="01000011"; current_state<=sg; when sg=>rs<='1';----写数据,字符o lcd_date<="01001111"; current_state<=sh; when sh=>rs<='1';----写数据,字符. lcd_date<="00101110"; current_state<=si; when si=>rs<='1';----写数据,字符C lcd_date<="01000011"; current_state<=sj; when sj=>rs<='1';----写数据,字符C lcd_date<="01000011"; current_state<=s0; when others=>rs<='1'; lcd_date<="01000000"; current_state<=s0; end case; end if; end process; end xianshi;