⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lcd.vhd

📁 EP1C6Q240C8的examples lcd测试程序
💻 VHD
字号:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;

entity lcd is
    Port ( clk : in std_logic;
	        delaytime : in std_logic;
           reset : in std_logic;
			  cs : out std_logic;
			  lcd_w : in std_logic;  
           codeout : out std_logic_vector(8 downto 0);
           en : out std_logic);
end lcd;

architecture Behavioral of lcd is
type instatetype is (S1,S2,S3,S4,S5,S6,
                     S7,S8);
signal pre_instate,next_instate : instatetype;



type datatype is array (0 to 15) of std_logic_vector(8 downto 0);
--WELCOME TO DZ51
CONSTANT DA1 : datatype :=("101010111","101000101","101001100","101000011",
                                "101001111","101001101","101000101","100100000",
										  "101010100","101001111","100100000","101000100",
										  "101011010","100110101","100110001","100100000");
-- ALTERA-SOPC 
CONSTANT DA2 : datatype :=("100100000","101000001","101001100","101010100","101000101",
                            "101010100","101000001",
                            "110110000", "110110000",
							"101010011","101001111","101010000", "101000011",
							"100100000","100100000","100100000");


signal en_ins,t_en_ins : std_logic;
signal t_code : std_logic_vector(8 downto 0);

signal en_cnt,t_en_cnt : std_logic;  
signal datacnt : integer range 0 to 15;

begin

  cs <= '1';



  process(delaytime,reset)
  begin
    if reset='0' then
	   en_cnt <= '0';
		en_ins <= '0';
		codeout <= (others=>'0');
	   pre_instate <= S1;
	 elsif (delaytime'event and delaytime='1') then
	   pre_instate <= next_instate;
		en_cnt <= t_en_cnt;
		en_ins <= t_en_ins;
		codeout <= t_code;
	 end if;
  end process;

  process(pre_instate,lcd_w)
  begin
    t_en_cnt <='0';
    t_en_ins <= '0';
	 t_code <= (others=>'0');
	 case pre_instate is
	   when S1 =>
		  if lcd_w='0' then
		    next_instate <= S2;
		  else
		    next_instate <= S1;
		  end if;
	   when S2=>
		    next_instate <= S3;
			 t_en_ins <= '1';
			 t_code <= "000000001";
      when S3 =>
		    next_instate <= S4;
			 t_en_ins <= '1';
			 t_code <= "000111000";
		when S4 =>
		    next_instate <= S5;
			 t_en_ins <= '1';
			 t_code <= "000001110";
		when S5 =>
		    next_instate <= S6;
			 t_en_ins <= '1';
			 t_code <= "000000110";  ----
			 t_en_cnt <= '1';
		when S6 =>   --write string to the first row
		  if datacnt=15 then
		    next_instate <= S7;
			 t_en_ins <= '1';
			 t_code <= DA1(datacnt);
		  else
		    next_instate <= S6;
          t_en_ins <= '1';
			 t_code <= DA1(datacnt);
		  end if;
		when S7 =>   
		  next_instate <= S8;
		  t_en_ins <= '1';
		  t_code <= "011000000";
		  t_en_cnt <= '1';
		when S8 =>   --write string to the second row
		  if datacnt=15 then
		    next_instate <= S1;
			 t_en_ins <= '1';
			 t_code <= DA2(datacnt);
		  else
		    next_instate <= S8;
          t_en_ins <= '1';
			 t_code <= DA2(datacnt);
		  end if;
		when others => next_instate <= S1;
	 end case;
  end process;
  ------------------------------------------------


  process(delaytime,t_en_cnt)
  begin
    if t_en_cnt='1' then
		  datacnt <= 0;
    elsif (delaytime'event and delaytime='1') then
		  datacnt <= datacnt + 1;
	 end if;
  end process;	

  process(clk,reset)
  begin
    if reset='0' then
	   en <= '0';
    elsif clk'event and clk='1' then
	   if delaytime='1' and en_ins='1' then
		  en <= '1';
		else
		  en <= '0';
		end if;
	 end if;
  end process;

end Behavioral;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -