|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?注册
x
- library ieee;
- use ieee.std_logic_1164.all;
- use ieee.std_logic_unsigned.all;
- entity lcd is
- port(clk:in std_logic;
- rst:in std_logic;
- rs:out std_logic;
- rw:out std_logic;
- ren:out std_logic;
- lcd_data:out std_logic_vector(7 downto 0));
- end lcd;
- architecture behav of lcd is
- type state is (set_function,set_clear,set_swtich,set_inmode,set_drram,set_writeram_1,set_writeram_2,set_idle);
- signal current_state:state:=set_clear;
- signal data_buf:std_logic_vector(7 downto 0);
- signal Clk_Out:std_logic;
- signal Lcd_clk:std_logic;
- signal cnt : std_logic_vector(20 downto 0);
- begin
- ren <= Clk_Out;
- div_clk:process(clk,rst)
- --variable cnt:integer:=0;
- --signal clk_buf:std_logic;
- begin
- if(rst = '0')then
- cnt <= (others => '0');
- elsif(rising_edge(clk))then
- cnt<= cnt + 1;
- if(cnt = 0)then
- Clk_Out <= not Clk_Out;
- end if;
- end if;
- LCD_clk <= Clk_Out;
- --begin
- --if rst='0'then
- -- cnt:=0;
- --elsif clk'event and clk='1' then
- --
- --if cnt<=55555 then
- -- clk_buf<='0';
- -- cnt:=cnt+1;
- --else
- -- clk_buf<=not clk_buf;
- -- cnt:=0;
- --end if;
- --end if;
- --ren<=clk_buf;
- end process div_clk;
-
- lcd_ctrl:process(Lcd_clk,rst,current_state)
- variable cntt:integer:=0;
- begin
-
- if (rst='0') then
- rs<='0';
-
- rw<='0';
- data_buf<="00000000";
- current_state<=set_clear;
- elsif Lcd_clk'event and Lcd_clk='1' then
- --cntt:=cntt+1;
-
- case current_state is
- when set_clear=>rs<='0';
- rw<='0';
- data_buf<="00000001";
- current_state<=set_function;
- when set_function=>rs<='0';
- rw<='0';
- data_buf<="00111000";
- current_state<=set_inmode;
- when set_inmode=>rs<='0';
- rw<='0';
- data_buf<="00000110";
- current_state<=set_swtich;
- when set_swtich=>rs<='0';
- rw<='0';
- data_buf<="00001100";
- current_state<=set_drram;
- when set_drram=>rs<='0';
- rw<='0';
- data_buf<="10000000";
- current_state<=set_writeram_1;
-
- when set_writeram_1=>rs<='1';
- rw<='0';
- if cntt=16 then
- cntt:=0;
- rs<='0';
-
- data_buf<="11000000";
- current_state<=set_writeram_2;
-
- else
- cntt:=cntt+1;
- case cntt is
- when 1=>data_buf<="01010111";
- when 2=>data_buf<="01010111";
- when 3=>data_buf<="01010111";
- when 4=>data_buf<="00101110";
- when 5=>data_buf<="01001110";
- when 6=>data_buf<="01000010";
- when 7=>data_buf<="01010101";
- when 8=>data_buf<="00101110";
- when 9=>data_buf<="01000101";
- when 10=>data_buf<="01000100";
- when 11=>data_buf<="01010101";
- when 12=>data_buf<="00101110";
- when 13=>data_buf<="01000011";
- when 14=>data_buf<="01001110";
- when 15=>data_buf<="10100000";
- when 16=>data_buf<="10100000";
-
- --current_state<=set_writeram_1;
- when others=>null;
- --cntt:=0;
- end case;
- current_state<=set_writeram_1;
- end if;
- when set_writeram_2=>rs<='1';
- rw<='0';
- if cntt=16 then
- cntt:=0;
- rs<='0';
- rw<='0';
- current_state<=set_idle;
- else
- --cntt:=0;
- cntt:=cntt+1;
- case cntt is
- when 1=>data_buf<="01010111";
- when 2=>data_buf<="01010111";
- when 3=>data_buf<="01010111";
- when 4=>data_buf<="00101110";
- when 5=>data_buf<="01001110";
- when 6=>data_buf<="01000010";
- when 7=>data_buf<="01010101";
- when 8=>data_buf<="00101110";
- current_state<=set_writeram_2;
- when 9=>data_buf<="01000101";
- when 10=>data_buf<="01000100";
- when 11=>data_buf<="01010101";
- when 12=>data_buf<="00101110";
- when 13=>data_buf<="01000011";
- when 14=>data_buf<="01001110";
- when 15=>data_buf<="10100000";
- when 16=>data_buf<="10100000";
-
- when others=>null;
- end case;
- current_state<=set_writeram_2;
- end if;
- when set_idle=>current_state<=set_idle;
- end case;
- lcd_data<=data_buf;
- end if;
-
-
- end process lcd_ctrl;
- end behav;
复制代码 我是要显示两行,因为lcd1602是两行的,但为什么程序写到第二行时(set_writeram_2)是从cntt=8那里执行,前面的不执行,结果第二行就显示了几个字符,第一行正常显示! |
|