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

📄 data_to_lcd.vhd

📁 Allegro原理图和PCB
💻 VHD
字号:
-- Data_to_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 ( lcd_data : out std_logic_vector (7 downto 4);
           clk        : in std_logic;
--           clk_mode        : in std_logic;
		   reset      : in std_logic;
		   lcd_enable : out std_logic;
           lcd_rs : out std_logic;
 		   lcd_rw : out std_logic );

end lcd ;


architecture behavioural of lcd is

type state_type is (warmup, setfunc, clear1, clear2, setmode1, setmode2, write1, home1, home2);

signal state : state_type;

attribute syn_state_machine : boolean;
attribute syn_state_machine of state : signal is true;  

signal count : std_logic_vector(3 downto 0);
signal finished : std_logic;         -- set high if done write cycle

signal  char_mode : std_logic_vector(1 downto 0);

--defining the disply
constant N: integer :=8;
type arr is array (1 to N) of std_logic_vector(7 downto 0);
constant display_char1 : arr := 	(X"A0", --blank
							x"41", --A
							x"43", --C
							X"54", --T
							X"45", --E
							X"4C", --L
							X"88", --blank
							X"88"); --blank

constant display_char2 : arr := 	(X"A0", --blank
							x"41", --A
							x"33", --3
							X"50", --P
							X"45", --E
							X"88", --blank
							X"88", --blank
							X"88"); --blank

constant display_char3 : arr := 	(X"53", --S
							x"54", --T
							x"41", --A
							X"52", --R
							X"54", --T
							X"45", --E
							X"52", --R
							X"88"); --blank

constant display_char4 : arr := 	(X"A0", --blank
							X"88", --blank
                            x"4B", --K
							x"49", --I
							X"54", --T
							X"88", --blank
							X"88", --blank
							X"88"); --blank

signal display_char : arr;

begin
	lcd_rw <= '0';
    lcd_enable <= clk; --not clk;  -- this is very important! if enable is not pulsed, lcd will not write

--    clk_mode_process: process (clk_mode, reset)
--    begin
--        if reset = '1' then
--			char_mode <= (others => '0');
--        elsif (clk_mode'event and clk_mode = '1') then
--            char_mode  <= char_mode + '1';
--        end if;
--
--    end process;
    	
    char_mode_process: process (char_mode)
    begin
        case char_mode  is
            when "00" =>
                display_char <= display_char1;
            when "01" =>
                display_char <= display_char2;
            when "10" =>
                display_char <= display_char3;
            when "11" =>
                display_char <= display_char4;
            when OTHERS  =>
                display_char <= display_char1;
    end case;
    end process;
    
    state_set: process (clk, reset, finished)
	begin
		if reset = '1' then
			count <= (others => '0');
            state <= warmup;--setfunc;            
            char_mode <= (others => '0');

		elsif (clk'event and clk = '1') then
			case state is
				when warmup =>
					lcd_rs <= '0';
					lcd_data <= "0011"; --"0000";  -- do nothing 
					if count = "0111" then  --0111
						count <= (others => '0');
						state <= setfunc;
					else
						count <= count + '1';
						state <= warmup;
					end if;
					
				when setfunc =>
					lcd_rs <= '0';
                    lcd_data <= "0010";
                    finished <= '0';

                    if count = "0010" then  --0010
						count <= (others => '0');
						state <= clear1;
                    else
						count <= count + '1';
                        state <= setfunc;
					end if;
				
                when clear1 =>
                 
					lcd_rs <= '0';
                    lcd_data <= "0000";
                    state <= clear2;
				
                when clear2 =>
				  lcd_rs <= '0';
                  if count = "0111" then                 
                    state <= setmode1;
                    count <= (others => '0');
                    lcd_data <= "1111";
                  else
                    count <= count + '1';
                    lcd_data <= "0001";
                    state <= clear1;
                  end if;
                    				
				when setmode1 =>
					lcd_rs <= '0';
                    lcd_data <= "0000";
					state <= setmode2;
                    finished <= '0';
				
                when setmode2 =>
					lcd_rs <= '0';
                    lcd_data <= "0110";
					state <= write1;

                                    											
				when write1 =>
					if finished = '1' then
						state <= home1;
                    --     count <= (others => '0');
					else					
						lcd_rs <= '1';
						count  <= count  + '1';
						state <= write1;
						CASE count IS
							WHEN "0000" =>
							    lcd_data <= display_char(1)(7 downto 4);
                            WHEN "0001" =>
							    lcd_data <= display_char(1)(3 downto 0);
                            WHEN "0010" =>
								lcd_data <= display_char(2)(7 downto 4);
							WHEN "0011" =>
							    lcd_data <= display_char(2)(3 downto 0);
							WHEN "0100"=>
								lcd_data <= display_char(3)(7 downto 4);			    		
							WHEN "0101"=>
								lcd_data <= display_char(3)(3 downto 0);
							WHEN "0110"=>
							    lcd_data <= display_char(4)(7 downto 4);
						    WHEN "0111"=>
							    lcd_data <= display_char(4)(3 downto 0);
							WHEN "1000" =>
							    lcd_data <= display_char(5)(7 downto 4);
						    WHEN "1001" =>
							    lcd_data <= display_char(5)(3 downto 0);
							WHEN "1010" =>
							    lcd_data <= display_char(6)(7 downto 4);
                            WHEN "1011" =>
							    lcd_data <= display_char(6)(3 downto 0);
							WHEN "1100" =>
							    lcd_data <= display_char(7)(7 downto 4);
                            WHEN "1101" =>
							    lcd_data <= display_char(7)(3 downto 0);
                            WHEN "1110" =>
							    lcd_data <= display_char(8)(7 downto 4);
                --            WHEN "1111" =>
	    		--			    lcd_data <= "0000";  -- 'blank'
		    				    finished <= '1';  -- needed to set done low before valid data is gone
                                char_mode  <= char_mode + '1';
                            WHEN OTHERS =>
							    lcd_data <= "0000";  -- ' '
						END CASE;
						

					end if;
                
                when home1 =>
					lcd_rs <= '0';
                    lcd_data <= "0000";
					state <= home2;
                    finished <= '0';
                    count <= (others => '0');
				
                when home2 =>
					lcd_rs <= '0';
                    lcd_data <= "0111";
					state <= write1;

                
			end case;
		end if;
	end process;
	
end behavioural;

⌨️ 快捷键说明

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