-- LCD output -- Takes the screen address and outputs them using LCD instructions. library ieee; library work; LIBRARY lpm; USE lpm.lpm_components.ALL; use work.LCD_types.all; use ieee.std_logic_1164.all; use ieee.std_logic_arith.all; use ieee.std_logic_unsigned.all; entity LCDout is port (address: in std_logic_vector(addressbit-1 downto 0); reset, clock:in std_logic; factor: in std_logic_vector(databit-1 downto 0); datascreen: in std_logic; command: out std_logic_vector(comm_bit-2 downto 0); enable: out std_logic); end entity LCDout; architecture behavior of LCDout is type state_type is (initial, clear, home, writestln1, modeset, displayon, funcset, funcset2, funcset3, funcset4, lastcharln1, writestln2, writestln2cont, writedata, lastcharln2, changeline, displayoff); signal state, nextstate : state_type; signal char : integer range 0 to num_char-1; signal count : integer range 0 to initialset; signal countval:integer range 0 to initialset; signal oldcount:integer range 0 to initialset; signal datasig:std_logic_vector(databit-1 downto 0); signal memdata:std_logic_vector(databit-1 downto 0); signal charaddress: std_logic_vector(addressbit-1 downto 0); begin -- This outputs the characters of the screen given the correct address StartROM : lpm_rom GENERIC MAP (LPM_WIDTH => databit, LPM_WIDTHAD => (addressbit), LPM_TYPE => "L_ROM", LPM_FILE => "lcdout.mif") -- note remember to call this initialization file -- the same as the original file PORT MAP (address => charaddress, inclock => clock, outclock => clock, q => memdata); -- This process ensures that there is an enable pulse for each instruction. -- It also keeps track of which character is being printed. enable_pulse : process (clock) begin if rising_edge(clock) then if count = 1 then if (state = home) then charaddress <= address; char<=0; else if (not(state = changeline)) then char <= char +1; charaddress <= charaddress +1; end if; end if; end if; if ((count <= oldcount-10)and(count > oldcount-(10+enabletime))) and (not(state = initial)) then enable <= '1'; else enable <= '0'; end if; end if; end process enable_pulse; -- This process outputs the correct instruction to make the LCD function display_char : process (clock) begin case state is -- The Initialization routine. --Reset Pressed when initial => nextstate <= funcset; countval <= initialset; -- First of 4 function sets. (8 bit data transfer) when funcset => nextstate <= funcset2; countval <= functime; when funcset2 => nextstate <= funcset3; countval <= functime; when funcset3 => nextstate <= funcset4; countval <= functime; when funcset4 => nextstate <= displayoff; countval <= cleartime; -- Turns off the display when displayoff => nextstate <= clear; countval <= cleartime; -- Clears the dispaly area when clear => nextstate <= modeset; countval <= functime; -- Sets the mode of the LCD screen to 2 lines when modeset => nextstate <= displayon; countval <= cleartime; -- Turns the display on when displayon => nextstate <= home; countval <= cleartime; -- End of initialization Routine -- ** Character Writing routine ** -- Home the cursor when home => nextstate <= writestln1; countval <= writetime; -- Write Line one until second last character when writestln1 => datasig<= memdata; if char = ((num_char/2)-1) then nextstate <= lastcharln1; countval<=writetime; else nextstate <= writestln1; countval <= writetime; end if; -- Write last character goto 2nd line when lastcharln1 => datasig<=memdata; nextstate <= changeline; countval <= functime; -- Changing to second line when changeline => datasig <=memdata; nextstate <=writestln2; countval <=writetime; -- Write 2nd line until get to 23 character (data character) when writestln2 => datasig <=memdata; if char = (22) then nextstate <= writedata; countval<=writetime; else nextstate <= writestln2; countval <= writetime; end if; -- Check whether to write character from memory or -- to write the betting factor when writedata => if datascreen = '1' then datasig <=factor; else datasig <= memdata; end if; nextstate <= writestln2cont; countval <= writetime; -- Finish second line when writestln2cont => datasig <=memdata; if char = ((num_char-1)) then nextstate <= lastcharln2; countval<=writetime; else nextstate <= writestln2cont; countval <= writetime; end if; -- Write last character when lastcharln2 => datasig <= memdata; nextstate <= home; countval <= cleartime; end case; end process display_char; -- Changes the state after delay period state_register:process(reset,clock) variable enablecheck : std_logic; begin if ((clock'event) and (clock='1')) then -- Synchronouus reset if reset = '0' then state <= initial ; count <= 0; -- Change state else if count = 0 then state <= nextstate; count <=countval; oldcount <=countval; else count <= count-1; end if; --end if; end if; end if; end process state_register; -- LCD instruction definition with state select command <= "0000000110" when modeset, "0000001100" when displayon, "0000001000" when displayoff, '1'&'0'&datasig when writestln1, '1'&'0'&datasig when lastcharln1, '1'&'0'&datasig when lastcharln2, '1'&'0'&datasig when writestln2, '1'&'0'&datasig when writedata, '1'&'0'&datasig when writestln2cont, "0011000000" when changeline, "0000000001" when clear, "0000000010" when home, "0000111000" when funcset, "0000111000" when funcset2, "0000111000" when funcset3, "0000111000" when funcset4, "0000000000" when others; end behavior;