------------------------------------------------------------------- -- ASCII HEX TABLE -- Hex Low Hex Digit -- Value 0 1 2 3 4 5 6 7 8 9 A B C D E F ------\---------------------------------------------------------------- --H 2 | SP ! " # $ % & ' ( ) * + , - . / --i 3 | 0 1 2 3 4 5 6 7 8 9 : ; < = > ? --g 4 | @ A B C D E F G H I J K L M N O --h 5 | P Q R S T U V W X Y Z [ \ ] ^ _ -- 6 | ` a b c d e f g h i j k l m n o -- 7 | p q r s t u v w x y z { | } ~ DEL ----------------------------------------------------------------------- LIBRARY IEEE; USE IEEE.STD_LOGIC_1164.all; USE IEEE.STD_LOGIC_ARITH.all; USE IEEE.STD_LOGIC_UNSIGNED.all; entity lcd_control is port ( trigger, sw_an, clk : in std_logic; ascii : in std_logic_vector(7 downto 0); lcd_rs, lcd_e, lcd_rw : out std_logic; lcd_data : out std_logic_vector(7 downto 0); led_test1 : out std_logic := '0'; lcd_an : out std_logic; sram_adress : out std_logic_vector(19 downto 0); sram_data : inout std_logic_vector(15 downto 0); sram_chip_enable : out std_logic; sram_write_enable_input : out std_logic; sram_output_enable_input : out std_logic; sram_lower_byte : out std_logic; sram_upper_byte : out std_logic ); end lcd_control; architecture behv of lcd_control is type state_type is (RESET1, RESET2, RESET3, DROP_E, HOLD, FUNC_SET, DISP_ON, DISP_CLEAR, MODE_SET, WAIT_CHAR, DISP_CLEAR_WAIT, WAIT_TRIGGER_RESET, CHK_CNT, LINE2, HOME); type state_type_sram is (SET_ADRESS, SET_DATA, HOLD_ADRESS); signal state_ram : state_type_sram := SET_ADRESS; signal state_ram_next : state_type_sram; signal state, next_command, satz_1, satz_2, satz_3 : state_type; signal char_cnt : std_logic_vector(5 downto 0); signal counter_buch : integer range 0 to 31 := 0; signal wait_cnt, pause, pause2 : std_logic_vector(24 downto 0); signal ascii_sig : std_logic_vector(7 downto 0); signal satz1ende : std_logic := '1'; signal schreibeprozess_ende : std_logic :='0'; signal sram_adress_counter : std_logic_vector(19 downto 0) := "00000000000000000001"; signal up_or_low : std_logic; signal esgehtlos : std_logic; SUBTYPE ascii1 IS STD_LOGIC_VECTOR(7 DOWNTO 0); TYPE charArray IS array(0 to 31) OF ascii1; constant satz1: charArray := (X"48", X"65", X"6c", X"6c", X"6f", X"20", X"57", X"6f", X"72", X"6c", X"72", X"6c", X"64", X"20", X"20", X"20", X"20", X"20", X"20", X"20", X"20", X"20", X"20", X"20", X"20", X"20", X"20", X"20", X"20",X"20",X"20", X"20" ); signal leerzeichen : std_logic_vector(7 DOWNTO 0) := "00000000"; begin lcd_rw<='0'; process begin wait until rising_edge(clk); lcd_an<='1'; if schreibeprozess_ende= '0' then if counter_buch < 28 then case state_ram is when SET_ADRESS => sram_adress<= sram_adress_counter; sram_write_enable_input<= '1'; sram_chip_enable<= '0'; sram_output_enable_input<='0'; sram_data(7 downto 0) <= satz1(counter_buch);-- plus 8 bit zahl; sram_data(15 downto 8) <= leerzeichen(7 downto 0); sram_lower_byte<='1'; sram_upper_byte<='1'; if wait_cnt < X"2710" then -- warten für 10000 Cycle, 200 ms wait_cnt <= wait_cnt +1; state_ram <= SET_ADRESS; else wait_cnt <= "0000000000000000000000000"; counter_buch<= counter_buch+1; sram_adress_counter<= sram_adress_counter + 1; state_ram <= SET_DATA; -- wait counter reset end if; when SET_DATA => sram_write_enable_input<= '0'; sram_lower_byte<='0'; sram_upper_byte<='0'; if wait_cnt < X"2710" then -- warten für 10000 Cycle, 200 ms wait_cnt <= wait_cnt +1; state_ram <= SET_DATA; else wait_cnt <= "0000000000000000000000000"; state_ram <= HOLD_ADRESS; -- wait counter reset end if; when HOLD_ADRESS => sram_write_enable_input<= '1'; sram_chip_enable<= '0'; sram_output_enable_input<='0'; sram_lower_byte<='1'; sram_upper_byte<='1'; if wait_cnt < X"2710" then -- warten für 10000 Cycle, 200 ms wait_cnt <= wait_cnt +1; state_ram <= HOLD_ADRESS; else wait_cnt <= "0000000000000000000000000"; state_ram <= SET_ADRESS; end if; end case; else schreibeprozess_ende <= '1'; sram_adress_counter<= "00000000000000000000"; counter_buch<= 1; end if; else case state is when RESET1 => -- erstes Kommando an LCD, mind. 16ms nach Einschalten lcd_rs <= '0'; sram_write_enable_input<='1'; lcd_data <= X"38"; -- 111000 - 8 bit - 2 Zeilen lcd_e <= '0'; led_test1<='1'; wait_cnt <= "0000000000000000000000000"; pause <= "0000000000000000000000000"; if wait_cnt < X"F4240" then -- warten für 10000 Cycle, 200 ms wait_cnt <= wait_cnt +1; state <= RESET1; else state <= DROP_E; -- Kommando an LCD next_command <= RESET2; wait_cnt <= "0000000000000000000000000"; -- wait counter reset end if; when RESET2 => lcd_rs <= '0'; lcd_data <= X"38"; lcd_e <= '0'; if wait_cnt < X"F4240" then -- Warteschleife für 200 ms --989680 --F4240 wait_cnt <= wait_cnt +1; state <= RESET2; else state <= DROP_E; next_command <= RESET3; wait_cnt <= "0000000000000000000000000"; end if; when RESET3 => lcd_rs <= '0'; lcd_data <= X"38"; lcd_e <= '0'; if wait_cnt < X"F4240" then -- Warteschleife für 200 ms wait_cnt <= wait_cnt +1; state <= RESET3; else state <= DROP_E; next_command <= FUNC_SET; wait_cnt <= "0000000000000000000000000"; end if; when FUNC_SET => lcd_rs <= '0'; lcd_data <= X"38"; lcd_e <= '0'; if wait_cnt < X"F4240" then -- Warteschleife für 200 ms wait_cnt <= wait_cnt +1; state <= FUNC_SET; else state <= DROP_E; next_command <= DISP_ON; wait_cnt <= "0000000000000000000000000"; end if; when DISP_ON => lcd_rs <= '0'; lcd_data <= X"0F"; lcd_e <= '0'; if wait_cnt < X"F4240" then -- Warteschleife für 200 ms wait_cnt <= wait_cnt +1; state <= DISP_ON; else state <= DROP_E; next_command <= DISP_CLEAR; wait_cnt <= "0000000000000000000000000"; end if; when DISP_CLEAR => lcd_rs <= '0'; lcd_data <= X"01"; lcd_e <= '0'; if wait_cnt < X"F4240" then -- clk period 1msec, warte 3 msec wait_cnt <= wait_cnt +1; state <= DISP_CLEAR; else wait_cnt <= "0000000000000000000000000"; state <= DROP_E; next_command <= DISP_CLEAR_WAIT; end if; when DISP_CLEAR_WAIT => if wait_cnt < X"F4240" then -- clk period 1msec, warte 3 msec wait_cnt <= wait_cnt +1; state <= DISP_CLEAR_WAIT; else state <= MODE_SET; -- Kommando an LCD wait_cnt <= "0000000000000000000000000"; end if; when MODE_SET => lcd_rs <= '0'; lcd_data <= X"06"; lcd_e <= '0'; char_cnt<="000000"; if wait_cnt < X"F4240" then -- Warteschleife für 200 ms wait_cnt <= wait_cnt +1; state <= MODE_SET; else state <= DROP_E; next_command <= WAIT_CHAR; wait_cnt <= "0000000000000000000000000"; esgehtlos<='1'; sram_write_enable_input<= '1'; end if; ---------------- Initialisierung beendet, Arbeitsloop ------------------------------------------- -- WAIT_CHAR -> DROP_E -> HOLD -> WAIT_TRIGGER_RESET -> CHK_CNT -> LINE2 -> DROP_E -> HOLD -> | -- | | -- ^ -> HOME -> DROP_E -> HOLD -> | -- | | | -- | v v -- |----------------------------------------<<-------------------------------------------| ------------------------------------------------------------------------------------------------- when WAIT_CHAR => if pause < X"F4240" then -- warten für 10000 Cycle, 200 ms pause <= pause +1; state <= WAIT_CHAR; sram_chip_enable<='0'; elsif char_cnt < X"1B" then pause <= "0000000000000000000000000"; -- wait counter reset lcd_rs<='1'; lcd_data <= sram_data(7 downto 0); sram_output_enable_input<='0'; sram_lower_byte<='0'; sram_upper_byte<='0'; char_cnt <= char_cnt +1; counter_buch<= counter_buch+1; lcd_e <= '0'; state <= DROP_E; next_command <= WAIT_TRIGGER_RESET; wait_cnt <= "0000000000000000000000000"; else state <= DROP_E; next_command <= DISP_CLEAR; char_cnt <= "000000"; end if; when WAIT_TRIGGER_RESET => if trigger = '0' then state <= WAIT_TRIGGER_RESET; else state<=DROP_E; next_command <= CHK_CNT; end if; when CHK_CNT => if char_cnt = X"11" then state <= DROP_E; next_command <= LINE2; elsif char_cnt = X"20" then state <= HOME; else state <= WAIT_CHAR; end if; when LINE2 => lcd_rs <= '0'; lcd_data <= X"C0"; lcd_e <= '0'; state <= DROP_E; next_command <= WAIT_CHAR; when HOME => lcd_rs <= '0'; lcd_data <= X"80"; -- Befehl Cursor wieder auf Start setzten char_cnt <= "000000"; lcd_e <= '0'; state <= DROP_E; next_command <= WAIT_CHAR; when DROP_E => if wait_cnt < X"F4240" then -- warten für 10000 Cycle, 200 ms wait_cnt <= wait_cnt +1; state<=DROP_E; sram_adress<=sram_adress_counter; else wait_cnt<="0000000000000000000000000"; lcd_e<='1'; if esgehtlos = '1' then sram_adress_counter<=sram_adress_counter+1; sram_chip_enable<='1'; sram_output_enable_input<='1'; end if; state <= HOLD; end if; when HOLD => if wait_cnt < X"F4240" then -- warten für 10000 Cycle, 200 ms wait_cnt <= wait_cnt +1; state<=HOLD; else wait_cnt<="0000000000000000000000000"; state <= next_command; end if; end case; end if; end process; end behv;